-1
<rss version="2.0">
<channel>
<title>Report</title>
<link>...</link>
<description>Report</description>
<pubDate>Tue, 29 Oct 2013 23:57:00 +0800</pubDate>
<copyright>SMG-2009. All rights reserved.</copyright>
<image>...</image>
<item>
<title>Report</title>
<link>...</link>
<guid isPermaLink="false">http://Report</guid>
<description>
<![CDATA[
在 2013-10-30 00:00 <br/> <table border="0"> <tr> <td rowspan="3"><img src="http://xml.gif" width="86" height="86"></td> <td>temperature:22 </td></tr> <tr><td>humidity:50% </td></tr> <tr><td>Wind:South ; Speed: 12 km/hr </td></tr> </table><br/><br/>
]]>
</description>
</item>
</channel>
</rss>

<?PHP
$weather = new DOMDocument();
          $weather -> load("abc.xml");
          $temp=$weather->getElementsByTagName('item')->item(0)->getElementsByTagName('description')->item(0)->childNodes->item(0)->nodeValue;
       //   $temp = iconv("UTF-8", "big5", $temp); 

    $temp = explode("<td>", $temp);

          $c = $temp[1];
          $h = $temp[2];

          echo $c . "----" . $h;

?>

//------------

现在我要检索的是温度的 $c 和湿度的 $h ,但是它失败了,对我的代码有什么建议吗?还有风和速度。

4

1 回答 1

0

尝试:

$weather -> load("abc.xml");
$temp=$weather->getElementsByTagName('item')->item(0)->getElementsByTagName('description')->item(0)->nodeValue;

preg_match_all('/<td>([^<]+)</', $temp, $matches);

$c = $matches[1][0];
$h = $matches[1][1];

echo $c . "----" . $h;
于 2013-10-29T17:21:47.593 回答