首页 > 学院 > 开发设计 > 正文

发一个天气预报接口

2019-11-06 08:46:47
字体:
来源:转载
供稿:网友
<?phpheader("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;?>
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表