Remove a child with a specific attribute, in SimpleXML for PHP

后端 未结 17 2382
星月不相逢
星月不相逢 2020-11-22 02:50

I have several identical elements with different attributes that I\'m accessing with SimpleXML:


    
    

        
17条回答
  •  不知归路
    2020-11-22 02:54

    Just unset the node:

    $str = <<
      
        
        
      
    
    STR;
    
    $xml = simplexml_load_string($str);
    unset($xml –> a –> b –> c); // this would remove node c
    echo $xml –> asXML(); // xml document string without node c
    

    This code was taken from How to delete / remove nodes in SimpleXML.

提交回复
热议问题