dt246813579 2013-10-29 09:08 采纳率: 0%
浏览 31
已采纳

从rss获取xml数据[关闭]

<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;

?>

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

Now What I want to retrieve is the $c for temperature and $h for humidity, but it fails, any advice on my code? Also the wind and speed as well.

展开全部

  • 写回答

1条回答 默认 最新

  • dongyao4003 2013-10-29 09:21
    关注

    Try:

    $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;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部