Chinaunix首页 | 论坛 | 博客
  • 博客访问: 802373
  • 博文数量: 42
  • 博客积分: 10080
  • 博客等级: 上将
  • 技术积分: 1970
  • 用 户 组: 普通用户
  • 注册时间: 2006-12-06 23:06
文章存档

2011年(1)

2010年(7)

2009年(4)

2008年(30)

我的朋友

分类:

2008-11-09 04:09:26

<?php
// Charset: utf-8
/**
 * 用php Simplexml 调用google天气预报api,和g官方的例子不一样
 * google 官方php domxml 获取google天气预报的例子
 *
 *
 * @copyright Copyright (c) 2008
 * @license New BSD License
 * @version 2008-11-9
 */


 // 城市,用城市拼音
$city = empty($_GET['city']) ? 'Nanning' : $_GET['city'];
$content = file_get_contents("");
$content || die("No such city's data");
$content = mb_convert_encoding($content, 'UTF-8', 'GBK');
$xml = simplexml_load_string($content);

$date = $xml->weather->forecast_information->forecast_date->attributes();
$html = $date. "
\r\n"
;

$current = $xml->weather->current_conditions;

$condition = $current->condition->attributes();
$temp_c = $current->temp_c->attributes();
$humidity = $current->humidity->attributes();
$icon = $current->icon->attributes();
$wind = $current->wind_condition->attributes();

$condition && $condition = $xml->weather->forecast_conditions->condition->attributes();
$icon && $icon = $xml->weather->forecast_conditions->icon->attributes();

$html.= "当前: {$condition}, {$temp_c}°C, {$humidity} {$wind}
\r\n"
;

foreach($xml->weather->forecast_conditions as $forecast) {
    $low = $forecast->low->attributes();
    $high = $forecast->high->attributes();
    $icon = $forecast->icon->attributes();
    $condition = $forecast->condition->attributes();
    $day_of_week = $forecast->day_of_week->attributes();
    $html.= "{$day_of_week} : {$high} / {$low} °C, {$condition}
\r\n"
;
}

header('Content-type: text/html; Charset: utf-8');
print $html;
?>

阅读(2266) | 评论(2) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2010-03-20 15:17:16

本文原创 如果文章中转或摘别人的东西均有声明 博客已转到 http://yulans.cn

chinaunix网友2010-03-18 17:01:00

垃圾 到处转摘 别人东西