多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國(guó)內(nèi)最全I(xiàn)T社區(qū)平臺(tái) 聯(lián)系我們 | 收藏本站
阿里云優(yōu)惠2
您當(dāng)前位置:首頁(yè) > php開(kāi)源 > php教程 > php獲取google當(dāng)前天氣實(shí)現(xiàn)程序

php獲取google當(dāng)前天氣實(shí)現(xiàn)程序

來(lái)源:程序員人生   發(fā)布時(shí)間:2014-05-12 19:28:05 閱讀次數(shù):2425次

我們會(huì)看到很多網(wǎng)站都可以實(shí)時(shí)的顯示當(dāng)時(shí)當(dāng)?shù)氐奶鞖?下面我來(lái)告訴你這種實(shí)時(shí)天氣的做吧,利用google aip接口即可實(shí)現(xiàn)獲取不同城市的天氣并顯示在自己網(wǎng)站上。

se.php,代碼如下:

  1. <?php 
  2. $city = $_GET['city']; 
  3. $data = createXml($city); 
  4.  
  5. $xml = simplexml_load_string($data); 
  6. header("Content-type: text/xml"); 
  7. echo $xml->asXML(); 
  8.  
  9. // 生成XML數(shù)據(jù) 
  10. function createXml($city
  11.     // Google 天氣API 
  12.     $weather = simplexml_load_file("http://www.google.com/ig/api?weather={$city}"); 
  13.     if(isset($weather->weather->forecast_conditions)) 
  14.     { 
  15.         $low = f2c($weather->weather->forecast_conditions->low['data']); 
  16.         $high = f2c($weather->weather->forecast_conditions->high['data']); 
  17.         return "<weather>n<city>{$city}</city>n<low>{$low}</low>n<high>{$high}</high></weather>n"
  18.     } 
  19.     else 
  20.     { 
  21.         return "<weather>n</weather>n"
  22.     } 
  23.  
  24. // 華氏度轉(zhuǎn)攝氏度 
  25. function f2c($fahrenhite
  26.     return floor(($fahrenhite - 32) / 1.8); 

客戶端 c.php,代碼如下:

  1. <html> 
  2. <head> 
  3. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
  4. <title>天氣查詢</title> 
  5. </head> 
  6. <body> 
  7. <form method="post" action=""
  8. <select name="city"
  9. <option value="0">請(qǐng)選擇</option> 
  10. <option value="beijing">北京</option> 
  11. <option value="shanghai">上海</option> 
  12. <option value="guangzhou">廣州</option> 
  13. <option value="wuhan">武漢</option> 
  14. </select> 
  15. <input type="submit" /> 
  16. </form> 
  17. <?php 
  18. if(!emptyempty($_POST['city'])) 
  19.     $city = $_POST['city']; 
  20.     $xml = simplexml_load_file("http://127.0.0.1/rest/se.php?city={$city}"); 
  21.     $html = "<p>City:{$xml->city}</p>n"
  22.     $html .= "<p>Low:{$xml->low}</p>n"
  23.     $html .= "<p>High:{$xml->high}</p>n"
  24.     echo $html
  25. ?> 
  26. </body> 
  27. </html>  
生活不易,碼農(nóng)辛苦
如果您覺(jué)得本網(wǎng)站對(duì)您的學(xué)習(xí)有所幫助,可以手機(jī)掃描二維碼進(jìn)行捐贈(zèng)
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關(guān)閉
程序員人生
主站蜘蛛池模板: 婷婷丁香综合 | 欧洲三级网站 | 亚洲综合三区 | 波多野吉衣 免费一区 | 包你爽综合网 | 欧美性猛交xxxxx按摩欧美 | 亚洲精品国产一区二区三 | 亚洲天堂在线视频播放 | 涩综合 | aⅴ免费在线观看 | 1024在线视频国产在线播放 | 色婷婷久久综合中文久久蜜桃 | 国产亚洲精品久久综合影院 | 日本一区视频在线播放 | 韩国在线观看免费观看影院 | 国产精品久久免费 | 欧美精品在线免费 | 在线视频免费观看 | 亚洲淫片| 手机看片福利视频 | 日韩爱爱网站 | 青青草原在线视频免费观看 | 国产精品毛片在线更新 | 日本久色| 欧美xxxx做受欧美精品 | 亚洲精品国产一区二区图片欧美 | 抖音毛片 | 日韩看片| 欧美成在线观看 | 日本一本在线视频 | 男女羞羞免费视频 | 国产欧美久久久另类精品 | 国产麻豆视频在线观看 | 天堂精品在线 | 国产精品第8页 | 精品一区二区三区五区六区 | 国产免费福利网站 | 伊人网亚洲 | 日本资源在线 | 成人精品福利 | 免费看黄色网址 |