标题: 一个从新浪获取当天天气的函数
时间: 2014-11-18
function sina_weather($city){
// 天气地址
$url = 'http://php.weather.sina.com.cn/iframe/index/w_cl.php?code=js&day=0&city='. $city .'&dfc=1&charset=utf-8';
// 从新浪获取天气数据
$file = file_get_contents($url);
// 从获取的数据中找到城市名
preg_match_all("@\['(.*)'\]@",$file,$city);
// 把城市名添加到数组当中
$weather['city'] = $city[1][0];
// 从获取的数据中找到天气数据
preg_match_all("@:'(.*?)'@s",$file,$data);
// 从新排列所找到的天气数据
list($weather['s1'], $weather['s2'], $weather['f1'], $weather['f2'], $weather['t1'], $weather['t2'], $weather['p1'], $weather['p2'], $weather['d1'], $weather['d2'], $weather['now'], $weather['time'], $weather['update'], $weather['error'], $weather['total']) = $data[1];
// 函数返回结果
return $weather;
}
『回复列表(3|隐藏机器人聊天)』