我正在为我的学校网站开发当前天气和天气预报的天气预报。为此,我将使用Yahoos RSS天气预报。在这个XML文件中,有一些值存储在属性中。我想用PHP来解决这些问题。该文件可在以下位置找到:http://weather.yahooapis.com/forecastrss?w=12602818&u=c
XML文件声明了以下行:
<rss xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0">我希望得到的值如下所示:
<yweather:condition text="Partly Cloudy" code="30" temp="22" date="Wed, 12 Jun 2013 4:20 pm CEST"/>例如,我想从yweather:条件中接收'temp‘。有没有人能告诉我怎么用PHP做到这一点?
发布于 2013-06-14 07:10:14
<?php
$doc = new DOMDocument();
$doc->load('http://weather.yahooapis.com/forecastrss?w=12602818&u=c');
$channel = $doc->getElementsByTagName("channel");
foreach($channel as $chnl){
$item = $chnl->getElementsByTagName("item");
foreach($item as $itemgotten){
$curtemp = $itemgotten->getElementsByTagNameNS("http://xml.weather.yahoo.com/ns/rss/1.0","condition")->item(0)->getAttribute("temp");
echo $curtemp;
}
}
?>这解决了这个问题!答案在这里:How to get the tag "" from Yahoo Weather RSS in PHP?
https://stackoverflow.com/questions/17068969
复制相似问题