Gen*_*nik 0 php xml rss simplexml
我这样做了
<blink>
$xml = file_get_contents(http://weather.yahooapis.com/forecastrss?w=12797541);
$yahoo_response = new SimpleXMLElement($xml , 0, true);
</blink>
Run Code Online (Sandbox Code Playgroud)
我得到了一个像这样的XML解析警告:
PHP Warning: SimpleXMLElement::__construct()
[<a href='simplexmlelement.--construct'>simplexmlelement.--construct</a>]:
I/O warning : failed to load external entity "<?xml version="1.0"
Run Code Online (Sandbox Code Playgroud)
.....
消息的一个重要部分是:
I/O warning : failed to load external entity
Run Code Online (Sandbox Code Playgroud)
我无法用这一行解析任何东西:
echo (string) $yahoo_response->rss->channel->item->title;
Run Code Online (Sandbox Code Playgroud)
有谁知道如何解决这个问题或绕过它?
谢谢,亚历克斯
第3个参数SimpleXMLElement()指定if是否$data为URL.你应该做任何一件事
$xml = file_get_contents('http://weather.yahooapis.com/forecastrss?w=12797541');
$yahoo_response = new SimpleXMLElement($xml , 0, false); // false, not true
Run Code Online (Sandbox Code Playgroud)
要么
$xml = 'http://weather.yahooapis.com/forecastrss?w=12797541'; // url, not contents
$yahoo_response = new SimpleXMLElement($xml , 0, true);
Run Code Online (Sandbox Code Playgroud)