- <?php
- header("Content-type:text/html;charset=utf-8");
- set_time_limit(0);
- $city='beijing';//城市代码
- $HTTP_Server="www.google.com";
- $HTTP_URL='/ig/api?hl=zh-cn&weather='.$city;
- $ch
= curl_init(); - curl_setopt
($ch,CURLOPT_URL,"http://".$HTTP_Server.$HTTP_URL); - curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
- curl_setopt($ch,CURLOPT_USERAGENT,"Mozilla/4.0
(compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)"); - $res
= curl_exec($ch); - curl_close
($ch); - $data=simplexml_load_string($res);
- $a
= $data->weather->current_conditions->condition[0][data]; - $b
= $data->weather->current_conditions->humidity[0][data]; - $c
= $data->weather->current_conditions->wind_condition[0][data]; - $w
= $a." ".$b.$c; - $ss
= date('Y年m月d日'); - $weekarray=array("日","一","二","三","四","五","六");
- $aa
= "星期".$weekarray[date("w")]; - echo
$str = $ss ." ".$aa." ".$w; - ?>
天气预报接口
最新推荐文章于 2020-05-06 18:49:13 发布