標籤:http io ar cti div html htm on
<?phpfunction 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);?>