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 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
{$temp_c['@attributes']['data']}°C
当前: {$conditions['@attributes']['data']}
{$wind_condition['@attributes']['data']}
{$humidity['@attributes']['data']}
$html
weather;
}
/**
* 打印样式
*/
static public function printCss() {
echo
大量免费API接口:立即使用
涵盖生活服务API、金融科技API、企业工商API、等相关的API接口服务。免费API接口可安全、合规地连接上下游,为数据API应用能力赋能!










