[英]cannot read yahoo xml feed in php
i am trying to read the yahoo rss (http://news.yahoo.com/rss/us) in php using the xml function 我正在尝试使用xml函数读取php中的yahoo rss(http://news.yahoo.com/rss/us)
this is myvery simple code: 这是非常简单的代码:
$xml = simplexml_load_file('xml.xml');
var_dump($xml['channel']);
but i shows NULL : 但我显示NULL :
adam@cka: php test.php
NULL
is my XML broken? 我的XML损坏了吗? or there's a better function in php to read xml file? 还是在php中有更好的功能来读取xml文件?
i can see the elment exists in the XML file and i downloaded the file correctly in my computer. 我可以看到该元素存在于XML文件中,并且我已将文件正确下载到计算机中。
SimpleXML returns an object, not an array. SimpleXML返回一个对象,而不是数组。 Try this: 尝试这个:
<?php
$xml = simplexml_load_file('http://news.yahoo.com/rss/us');
var_dump($xml->channel);
?>
Something like this: 像这样:
$rss = simplexml_load_file('http://news.yahoo.com/rss/us'); echo $rss->channel->title; foreach ($rss->channel->item as $item) { echo $item->link. " -- " .$item->title; echo $item->pubDate; echo $item->description; }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.