php代码
<? //- Describe: //- Author: liuguichun //- Link: //- CreateTime: 2010-6-21 //- UpdateTime: //- Package: class weather { static $url = 'http://www.google.com/ig/api?hl=zh-cn&weather='; static $city = 'Beijing'; //默认城市北京 static $weatherXML = ''; /** * 获得远程xml并缓存到本地 */ static public function getXML() { header ( 'Content-Type: text/html; charset = utf-8' ); if (isset ( $_GET ['city'] )) { self::$city = empty ( $_GET ['city'] ) ? 'Beijing' : $_GET ['city']; } $contents = file_get_contents ( self::$url . self::$city ) or die ( '查询出错' ); self::$weatherXML = date ( "Ymd" ) . '-' . self::$city . '-weather.xml'; if (is_file ( self::$weatherXML )) { $fileTime = filemtime ( self::$weatherXML ); $stater = time () - $fileTime - 60 * 60 * 2; if ($stater < 0) { self::cacheXML ( $contents ); } return true; } self::cacheXML ( $contents ); } /** * 解析xml */ static public function analysisXML() { if (is_file ( self::$weatherXML )) { $xml = simplexml_load_file ( self::$weatherXML ); } else { $xml = simplexml_load_file ( self::$url . self::$city ); } $xml = ( array ) $xml; $city = ( array ) $xml ['weather']->forecast_information->city; if (isset ( $xml ['weather']->problem_cause )) { $problem = ( array ) $xml ['weather']->problem_cause; echo $problem ['@attributes'] ['data']; return; } $conditions = ( array ) $xml ['weather']->current_conditions->condition; $humidity = ( array ) $xml ['weather']->current_conditions->humidity; $temp_c = ( array ) $xml ['weather']->current_conditions->temp_c; $conditions_icon = ( array ) $xml ['weather']->current_conditions->icon; $wind_condition = ( array ) $xml ['weather']->current_conditions->wind_condition; $forecast = ( array ) $xml ['weather']; $forecast = ( array ) $forecast ['forecast_conditions']; $html = ''; foreach ( $forecast as $key => $val ) { ${'day_of_week_' . $key} = ( array ) $val->day_of_week; ${'low_' . $key} = ( array ) $val->low; ${'high_' . $key} = ( array ) $val->high; ${'icon_' . $key} = ( array ) $val->icon; ${'condition_' . $key} = ( array ) $val->condition; $html .= " {${'day_of_week_'.$key}['@attributes']['data']} http://www.google.com{${'icon_'.$key}['@attributes']['data']}\ " width=40 height=40> {${'low_'.$key}['@attributes']['data']}°C | {${'high_'.$key}['@attributes']['data']}°C "; } self::printCss (); echo << {$city['@attributes']['data']} http://www.google.com{$conditions_icon['@attributes']['data' ]}" width=40 height=40> {$temp_c['@attributes']['data']}°C 当前: {$conditions['@attributes']['data']} {$wind_condition['@attributes']['data']} {$humidity['@attributes']['data']} $html weather; } /** * 打印样式 */ static public function printCss() { echo << css; } /** * 创建xml缓存 * @param $contents 要缓存的内容 */ static private function cacheXML($contents) { $contents = str_ireplace ( '', " \n", $contents ); $contents = mb_convert_encoding ( $contents, 'utf-8', 'gbk' ); file_put_contents ( self::$weatherXML, $contents ) or die ( '没有写权限' ); } } weather::getXML (); weather::analysisXML (); ?>
陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章
R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
4 週前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳圖形設置
4 週前By尊渡假赌尊渡假赌尊渡假赌
刺客信條陰影:貝殼謎語解決方案
2 週前ByDDD
R.E.P.O.如果您聽不到任何人,如何修復音頻
4 週前By尊渡假赌尊渡假赌尊渡假赌
WWE 2K25:如何解鎖Myrise中的所有內容
1 個月前By尊渡假赌尊渡假赌尊渡假赌

熱工具

SublimeText3漢化版
中文版,非常好用

Atom編輯器mac版下載
最受歡迎的的開源編輯器

VSCode Windows 64位元 下載
微軟推出的免費、功能強大的一款IDE編輯器

禪工作室 13.0.1
強大的PHP整合開發環境

DVWA
Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中