我在查询网络服务(雅虎天气)时遇到问题。感谢这个很酷的论坛,我找到了以下提示。然而,我无法找回我的价值。
我正在使用提取 CDATA 部分
$conditionIcon = $weatherXmlObject->xpath("//item/description");
$dom = new DOMDocument();
$dom->loadHTML($conditionIcon); // or you can use loadXML
$xml = simplexml_import_dom($dom);
$imgSrc = (string)$xml->body->img['src'];
echo $imgSrc;
$imgSrc 始终为空。
描述看起来像这样
<description><![CDATA[
<img src="http://l.yimg.com/a/i/us/we/52/28.gif"/><br />
<b>Current Conditions:</b><br />
Mostly Cloudy, 50 F<BR />
<BR /><b>Forecast:</b><BR />
Fri - Partly Cloudy. High: 62 Low: 49<br />
Sat - Partly Cloudy. High: 65 Low: 49<br />
<br />
<a href="http://us.rd.yahoo.com/dailynews/rss/weather/Sunnyvale__CA/*http://weather.yahoo.com/forecast/USCA1116_f.html">Full Forecast at Yahoo! Weather</a><BR/><BR/>
(provided by <a href="http://www.weather.com" >The Weather Channel</a>)<br/>
]]></description>