php 抓取天氣情況 www.weather.com.cn

來源:互聯網
上載者:User

標籤: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);?>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.