当前位置 : 主页 > 网络编程 > PHP >

weather.php

来源:互联网 收集:自由互联 发布时间:2021-06-28
weather.php code=='1'){ return false; } $data = $ip-data-city;return $data;}function getWeather($cityId){$url="http://www.weather.com.cn/data/sk/".$cityId.".html";$weather=json_decode(file_get_contents($url));return $weather;}function json_
weather.php
 code=='1'){
	   return false;
 	}
 	$data = $ip->data->city;
	return $data;	
}

function getWeather($cityId)
{
	$url="http://www.weather.com.cn/data/sk/".$cityId.".html";
	$weather=json_decode(file_get_contents($url));
	return $weather;	
}
function json_to_array($web){
	$arr=array();
	foreach($web as $k=>$w){
		if(is_object($w)) $arr[$k]=json_to_array($w); //判断类型是不是object
		else $arr[$k]=$w;
	}
	return $arr;
}
$city = getCity(getIP());
//$city = getCity('202.103.24.68');
//var_dump($city);die;
$city = str_split($city,strlen($city)-3);
$city =$city[0];
$cityUrl = "http://evenle.com/wei/20130921/city.php";
$web=json_decode(file_get_contents($cityUrl));
$arr=json_to_array($web);
$weatherInfo = getWeather($arr[$city]);
echo(json_encode($weatherInfo));

?>
网友评论