Parsing XML into Array

后端 未结 2 772
独厮守ぢ
独厮守ぢ 2020-12-12 06:53

So i have this XML structure:


    
    

        
相关标签:
2条回答
  • 2020-12-12 07:27
    $xml = simplexml_load_string($xml);
    $fields = array();
    foreach ($xml->field as $f) {
        $f = (array) $f->attributes();
        $fields[] = $f['@attributes'];
    }
    
    0 讨论(0)
  • 2020-12-12 07:40
    $dom = new DOMDocument;
    $dom->loadXML($xml);
    $fields = $dom->getElementsByTagName('field');
    $arr = array();
    foreach ($fields as $field) {
      $arr[] = array(
        'name' => $field->getAttribute('name'),
        'label' => $field->getAttribute('label');
        'size' => $field->getAttribute('size'),
      );
    }
    
    0 讨论(0)
提交回复
热议问题