Json Encode or Serialize an XML

后端 未结 5 1268
-上瘾入骨i
-上瘾入骨i 2020-12-22 06:01

I have some xml, this is a simple version of it.



  item one
  item two         


        
5条回答
  •  再見小時候
    2020-12-22 06:21

    You need to call attributes() function.

    Sample code:

    $xmlString = '
    
      item one
      item two
    
    ';
    
    $xml = new SimpleXMLElement($xmlString);
    
    foreach( $xml->items->item as $value){
    $my_array[] =  strval($value->attributes());
    }
    
    print_r($my_array);
    

    Eval

提交回复
热议问题