php抓取天气,php 抓取天气情况 www.weather.com.cn

print_r(getweather(101120501));

/**

* Server 天气情况获取函数

* @param unknown $city

*/

function getweather($city){

$url = "http://www.weather.com.cn/weather1d/".$city.".shtml";

$result = file_get_contents($url);

$result = explode("

",$result);

$result = explode("

",$result[1]);

$result = mb_convert_encoding($result[0],"GBK","UTF-8");

$first = explode("

//print_r($first);exit;

$w1 = get_we_info($first[0]);

$w2 = get_we_info($first[1]);

$week = mb_substr($w1[0],-2);

$arr['w_week'] = $week;

$arr['w_day1'] = trim($w1[1]);

$arr['w_day2'] = trim($w2[1]);

$arr['w_type1'] = trim($w1[2]);

$arr['w_type2'] = trim($w2[2]);

$arr['w_temperature1']= trim($w1[3]);

$arr['w_temperature2']= trim($w2[3]);

return $arr;

}

/**

* 每天的具体天气状况(今天 白天->今天 夜间)

* @param unknown $info

* @return string

*/

function get_we_info($info){

$w_info=explode("",$info);

$we_arr[0] = strip_tags($w_info[0]);

$w_info=explode("",$w_info[1]);

$we_arr[1] = strip_tags($w_info[0]);

$w_info = explode("

",$w_info[1]);

$we_arr[2] = strip_tags($w_info[0]);

$w_info=explode("",$w_info[1]);

//$w_info=explode("

",$w_info[1]);

$we_arr[3]=strip_tags($w_info[0]);

return $we_arr;

}

?>

原文:http://www.cnblogs.com/bhlsheji/p/5204646.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值