2013年1月17日 星期四

用PHP下載雅虎Yahoo天氣Data


好都客戶都想在他們的Website display下本地的時間/日期/天氣.!
時間/日期可用Javascript去display你的電腦的setting.!

天氣的Data便要下載!
Google的Weather API已Expired.!
現在要用Yahoo的Data.!
用DOM去load一條Yahoo Link!

<?php
$weather = new DOMDocument();
$weather->load('http://weather.yahooapis.com/forecastrss?p=CHXX0049&u=c');
$data1 = $weather->getElementsByTagName("channel");

foreach($data1 as $channel) {
$data2 = $channel->getElementsByTagName("item");
foreach($data2 as $description) {
$node = $description->getElementsByTagName("description");
$info = $node->item(0)->nodeValue;
echo $info;
}
}
?>


沒有留言:

張貼留言