可能的重复:
PHP 的最佳 XML 解析器 https://stackoverflow.com/questions/188414/best-xml-parser-for-php
我有一个包含 XML 数据的字符串。我如何在 PHP 中解析它?
谢谢
尝试用简单的XML http://php.net/manual/en/book.simplexml.php,这是一个例子:
do.php:
<?php
$xml_str = file_get_contents('xmlfile.xml');
$xml = new SimpleXMLElement($xml_str);
$items = $xml->xpath('*/item');
foreach($items as $item) {
echo $item['title'], ': ', $item['description'], "\n";
}
xml文件.xml:
<?xml version="1.0" encoding="UTF-8"?>
<xml>
<items>
<item title="Hello World" description="Hellowing the world.." />
<item title="Hello People" description="greeting people.." />
</items>
</xml>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)