开发者

Error/Warning parsing RSS XML :(

I did this

<blink>
$xml = file_get_contents(http://weather.yahooapis.com/forecastrss?w=12797541);
$yahoo_response = new SimpleXMLElement($xml , 0, true);
</blink>

And I got an XML parse warning like this:

PHP Warning:  SimpleXMLElement::__construct()
[<a href='simplexmlelement.--construct'>simplexmlelement.--construct</a>]:
I/O warning : faile开发者_运维技巧d to load external entity &quot;&lt;?xml version=&quot;1.0&quot; 

.....

With an important part of the message being this:

I/O warning : failed to load external entity 

And I could not parse anything with this line:

echo (string) $yahoo_response->rss->channel->item->title;

Does anyone know how to fix this or get around it?

Thanks, Alex


3rd argument of SimpleXMLElement() specifies if $data is URL. You should do either

$xml = file_get_contents('http://weather.yahooapis.com/forecastrss?w=12797541');
$yahoo_response = new SimpleXMLElement($xml , 0, false); // false, not true

or

$xml = 'http://weather.yahooapis.com/forecastrss?w=12797541'; // url, not contents
$yahoo_response = new SimpleXMLElement($xml , 0, true);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜