php调用天气预报api接口,php调用google api 天气预报

注意编码UTF8

$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. "
\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="

   

{$temp_c}°C
   
%7B%24icon%7D
   
ys.png ys1.png ys2.png ys3.png ys4.png ys5.png
"; // print $html;exit; //$html.= "当前: {$condition}, {$temp_c}°C, %7B%24icon%7D {$humidity} {$wind}
\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} www.google.com%7B%24icon%7D
\r\n";

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值