PHP城市级联|采集自中国天气网

字体大小: 中小 标准 ->行高大小: 标准

<?php 

02 header("Content-Type:text/html; charset=utf-8"); 

03   

04 for($i=0; $i<35; $i++){ 

05     if($i==0) $i = ''; 

06     elseif($i<10) $i = '0'.$i; 

07   

08 $url = 'http://www.weather.com.cn/data/listinfo/city'.$i.'.xml'; 

09 $context = stream_context_create( 

10     array( 

11         'http' => array( 

12             'timeout' => 3 

13         ) 

14     ) 

15 ); 

16 $xml = file_get_contents($url, false, $context);   

17 $arr = explode(',', $xml); 

18 $str = 'public static function city'.$i.'(){ 

19         return array( 

20         '; 

21 foreach($arr as $val){ 

22     $prov = explode('|', $val); 

23     $str .= "   '".$prov[0]."' => '".$prov[1]."', "; 

24 } 

25   

26 print $str.' 

27         ); 

28     } 

29       

30     '; 

31 }

此文章由 http://www.ositren.com 收集整理 ,地址为: http://www.ositren.com/htmls/29889.html