21,893
社区成员




<item>
<title>Wednesday: snny int, Max Temp: 16°C (61°F), Min Temp: 8°C (46°F)</title>
<link>http://www.bbc.co.uk</link>
<description>Max Temp: 16°C (61°F), Min Temp: 8°C (46°F), Wd Dtn: ESE, Wd Spd: 3mph, Vbt: poor, Prre: 1024mb, Humdty: 72%,
UV rk: low,
Plltn: low,
Srise: 06:40BST, Sset: 19:18BST</description>
<guid isPermaLink="false">tag:feeds.bbc.co.uk,(none)</guid>
<pubDate>Wed, 17 Sep 2008 08:40:15 +0000</pubDate>
<geo:lat>54.05</geo:lat>
<geo:long>-1.25</geo:long>
</item>
<item>
<title>Thursday: snny, Max Temp: 17°C (63°F), Min Temp: 8°C (46°F)</title>
<link>http://www.bbc.co.uk</link>
<description>Max Temp: 17°C (63°F), Min Temp: 8°C (46°F), Wd Dtn: SSE, Wd Spd: 3mph, Vbt: very poor, Prre: 1025mb, Humdty: 58%,
UV rk: low,
Plltn: low,
Srise: 06:42BST, Sset: 19:16BST</description>
<guid isPermaLink="false">tag:feeds.bbc.co.uk,(none)</guid>
<pubDate>Wed, 17 Sep 2008 08:40:15 +0000</pubDate>
<geo:lat>54.05</geo:lat>
<geo:long>-1.25</geo:long>
</item>
<item>
<title>Friday: lt ran, Max Temp: 17°C (63°F), Min Temp: 8°C (46°F)</title>
<link>http://www.bbc.co.uk</link>
<description>Max Temp: 17°C (63°F), Min Temp: 8°C (46°F), Wd Dtn: WSW, Wd Spd: 5mph, Vbt: good, Prre: 1028mb, Humdty: 79%,
UV rk: low,
Plltn: low,
Srise: 06:44BST, Sset: 19:13BST</description>
<guid isPermaLink="false">tag:feeds.bbc.co.uk,(none)</guid>
<pubDate>Wed, 17 Sep 2008 08:40:15 +0000</pubDate>
<geo:lat>54.05</geo:lat>
<geo:long>-1.25</geo:long>
</item>
$xml = simplexml_load_file('http://feeds.bbc.co.uk/weather/feeds/rss/5day/id/2315.xml');
foreach( $xml->channel->item as $item )
{
$arr = (array)$item;
$params = array();
//title
if(preg_match( '/^[^:]+:([^,]+)/is',$arr['title'],$tmp ) )
$params['Title'] = $tmp[1];
//description
$strs = explode( ',',$arr['description'] );
foreach( $strs as $v )
{
$tmp = explode( ': ',$v );
$params[trim($tmp[0])]=$tmp[1];
}
//pubdate
$params['pubDate'] = $arr['pubDate'];
echo '<pre>';
print_r( $params );
echo '</pre>';
}
function substr1($startstr,$endstr,$str)
{
$allstrnum = strlen($str);//取总字符串长度
$indexnum = $allstrnum-strlen(strstr($str,$startstr));//去指定字符串的索引值
$strright = Substr($str,$indexnum);//去除指定字符串的左边
$strnum = $allstrnum-strlen(strstr($str,$endstr));//取指定字符串的索引值
$f = Substr($strright,0,$strnum);//去除右边
$g = Substr(Trim($f),strlen($startstr));//得到数字
return Trim($g);
}
$doc=new DOMDocument();
$doc->load('xxx.xml');
$titles=$doc->getElementsByTagName("item");
$vla=$titles->item(0)->nodeValue;
echo substr1("Wednesday:","Max Temp",$vla);//显示snny int