Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用PHP解析XML_Php_Xml - Fatal编程技术网

用PHP解析XML

用PHP解析XML,php,xml,Php,Xml,这就是我的XML的样子 <?xml version="1.0" encoding="UTF-8"?> <item> <date>May 2013</date> <html>http://www.link.to/html.html</html> </item> 2013年5月 http://www.link.to/html.html 我在PHP中实现了这一点,并且它可以正常工作 $fi

这就是我的XML的样子

<?xml version="1.0" encoding="UTF-8"?>
  <item>
    <date>May 2013</date>
    <html>http://www.link.to/html.html</html>
  </item>

2013年5月
http://www.link.to/html.html
我在PHP中实现了这一点,并且它可以正常工作

$file = '../modules/xml/nl-archive.xml';
$xml = simplexml_load_file($file);
$string = '';
foreach($xml as $item){
    $string .= '<a href="'.$item->html .'" ><li>'.$item->date .'</li></a>';
}
$file='../modules/xml/nl archive.xml';
$xml=simplexml\u load\u文件($file);
$string='';
foreach($xml作为$item){
$string.='';
}

只是想让date标签和html标签的内容显示在每个item标签上。我一直在谷歌上搜索和修补,没能把它弄对。我做错了什么

尝试将XML更改为具有子级的根,如:

<?xml version="1.0" encoding="UTF-8"?>
<items>
    <item>
        <date>May 2013</date>
        <html>http://www.link.to/html.html</html>
    </item>
</items>

2013年5月
http://www.link.to/html.html

Php就像您拥有的一样好。

尝试更改您的XML,使其具有一个包含以下子项的根:

<?xml version="1.0" encoding="UTF-8"?>
<items>
    <item>
        <date>May 2013</date>
        <html>http://www.link.to/html.html</html>
    </item>
</items>

2013年5月
http://www.link.to/html.html

Php就像您拥有的一样好。

Ohhhh!我知道
simplexml\u load\u file()
通常只加载根标记,因此我认为是否有根并不重要。现在完全有道理了。非常感谢!哦!我知道
simplexml\u load\u file()
通常只加载根标记,因此我认为是否有根并不重要。现在完全有道理了。非常感谢!