首页 > Web开发 > 详细

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

时间:2014-08-19 09:26:13      阅读:384      评论:0      收藏:0      [点我收藏+]
<?php


function getweather($city){


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


	$arr=explode("<li class='dn on' data-dn='todayT'>",$result);
	$arr1=explode("<div class=\"m m2\" id=\"2_3d\">",$arr[1]);


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


	$wt1=explode("</i> </p>",$wt);


	$first=explode("</h1>",$wt1[0]);
	$w1_1=$first[0];
	//echo strip_tags($w1_1);//当前状态(第一个天气情况)
	$w1_2=explode("<p class=\"tem\">",$first[1]);
	//echo strip_tags($w1_2[0]);//天气
	//echo strip_tags($w1_2[1]);//温度


	$sec=explode("<h1>",$wt1[1]);
	$second=explode("</h1>",$sec[1]);
	$w2_1=$second[0];
	//echo strip_tags($w2_1);//当前状态(第二个天气情况)
	$w2_2=explode("<p class=\"tem\">",$second[1]);
	//echo strip_tags($w2_2[0]);//天气
	//echo strip_tags($w2_2[1]);//温度
	
	$weekday=array('天','一','二','三','四','五','六');
	$showtime=date("d号 星期").$weekday[date("w")];


	
	//first温度
	$firstwd=explode("°", trim(strip_tags($w1_2[1])));
	
	$str="[今天] ".$showtime.strip_tags($w1_1)."至".strip_tags($w2_1)." ".trim(strip_tags($w1_2[0]))."转".trim(strip_tags($w2_2[0]))." ".$firstwd[0]."/".trim(strip_tags($w2_2[1]));
	echo $str;
}
getweather(101120501);


?>

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

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

原文:http://blog.csdn.net/zxlstudio/article/details/38676861

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!