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 "<?xml version="1.0"
.....
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);
精彩评论