可能重复:
PHP - How to parse this xml?
Parse xml with php - storing parts into array(接近删除或已删除)
如果我有以下XML文件,并且我想将标记name
和number
中的值保存到名为department
的数组中,我怎样才能使用PHP?
<?xml version="1.0"?>
<data>
<record id="1">
<department>
<name>ACME</name>
<number>5</number>
</department>
<floor>
<name>ACME Floor</name>
<number>5</number>
</floor>
</record>
</data>
答案 0 :(得分:2)
你应该使用
DOMDocument :: loadXML
<?php
$doc = new DOMDocument();
$doc->load('book.xml');
$books = $dom->getElementsByTagName('book');
foreach ($books as $book) {
echo $book->nodeValue, PHP_EOL;
}
?>