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.能量晶体解释及其做什么(黄色晶体)
3 周前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳图形设置
3 周前By尊渡假赌尊渡假赌尊渡假赌
刺客信条阴影:贝壳谜语解决方案
1 周前ByDDD
R.E.P.O.如果您听不到任何人,如何修复音频
3 周前By尊渡假赌尊渡假赌尊渡假赌
在哪里可以找到原子中的起重机控制钥匙卡
1 周前ByDDD

热工具

mPDF
mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),

SublimeText3 英文版
推荐:为Win版本,支持代码提示!

MinGW - 适用于 Windows 的极简 GNU
这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。

ZendStudio 13.5.1 Mac
功能强大的PHP集成开发环境

禅工作室 13.0.1
功能强大的PHP集成开发环境