How to convert DOMNodeList object into array

后端 未结 5 560
春和景丽
春和景丽 2021-01-03 22:58

I have this code:

     $dom = new DOMDocument();
     $dom->load(\'file.xml\');
     $names = $dom->getElementsByTagName(\'name\');

N

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-03 23:28

    Assuming you want the actual values and not to create an array of DOM nodes:

    foreach($nodelist as $node) {
        $values[] = $node->nodeValue;
    }
    

提交回复
热议问题