php调用google api 天气预报

php调用google api 天气预报
2010-07-02 10:23

注意编码UTF8

<?php
header('Content-type: text/html; Charset:utf-8');
// 城市,用城市拼音
$city = empty($_GET['city']) ? 'chongqing' : $_GET['city'];

$content = @file_get_contents("

if(empty($content)){
exit;
}

$content=iconv('gb2312','utf-8', $content);

$xml = simplexml_load_string($content);
$date = $xml->weather->forecast_information->forecast_date->attributes();
$html = $date. "<br>\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="
<div class='tianqi-kuang'>
<div class='dizhi'><br />{$temp_c}°C</div>
<div class='sun'><img src={$icon} /></div>
<div class='yans'><img src='img/ys.png' width='11' height='10' /><img src='img/ys1.png' width='11' height='10' /><img src='img/ys2.png' width='11' height='10' /><img src='img/ys3.png' width='11' height='10' /><img src='img/ys4.png' width='11' height='10' /><img src='img/ys5.png' width='11' height='10' /></div>
</div>";
// print $html;exit;
//$html.= "当前: {$condition}, {$temp_c}°C,<img src='{$icon}'/> {$humidity} {$wind} <br />\r\n";

$ssss=$xml->weather->forecast_conditions;
$low = $ssss[0]->low->attributes();
$high = $ssss[0]->high->attributes();
$icon=$ssss[0]->icon->attributes();
$condition =$ssss[0]->condition->attributes();
$day_of_week = $ssss[0]->day_of_week->attributes();
$html.= "{$day_of_week} : {$high} / {$low} °C, {$condition} <img src='http://www.google.com{$icon}' /><br />\r\n";

$html=iconv('utf-8','gb2312', $html);
print $html;
?>

你可能感兴趣的:(google api)