php如何獲取指定地區(qū)天氣
導語:php如何獲取指定地區(qū)天氣呢?下面是小編給大家推薦的代碼實現(xiàn),大家可以參考閱讀,更多詳情請關注應屆畢業(yè)生考試網。
PHP 獲取指定地區(qū)的天氣
在開發(fā)網站的時候用到天氣查詢,由于是基于Wordpress的 所以有很多限制,先建一個【weather.PHP】的文件,然后看代碼:
<?php
/pic/p>
$url = '/pic/data/';
$id = '101181101'; /pic/p>
$data = file_get_contents($url . $id .'.html');
$obj=json_decode($data);
echo $obj->weatherinfo->city.':'.$obj->weatherinfo->weather1.' '.$obj->weatherinfo->temp1;
而對于:
$obj=json_decode($data);
它是把獲取的json數(shù)據轉化為一個對象,方便調用;
那么最后一句:
echo $obj->weatherinfo->city.':'.$obj->weatherinfo->weather1.' '.$obj->weatherinfo->temp1;
就是獲取指定的數(shù)據并按照一定格式輸出,
$obj->weatherinfo->city /pic/p>
$obj->weatherinfo->weather1 /pic/p>
$obj->weatherinfo->temp1 /pic/p>
最后 在需要顯示的地方
<?php include 'weather.php' ?>
即可。
【php如何獲取指定地區(qū)天氣】相關文章:
PHP如何獲取表單10-26
PHP如何獲取系統(tǒng)信息02-02
如何利用PHP語言獲取連接信息11-04
php通過Chianz.com獲取IP地址與地區(qū)的方法11-18
如何實現(xiàn)PHP獲取表單數(shù)據與HTML嵌入PHP腳本01-16
PHP獲取星期的方法08-08
php怎么獲取input的id08-25