Home > php教程 > PHP源码 > PHP城市级联|采集自中国天气网

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

PHP中文网
Release: 2016-05-25 17:04:20
Original
1341 people have browsed it

从中国天气网采集过来的,他们这里的城市级联信息比较准确和丰富,
把每一个省市的城市及对应区号以数组的键值存放。

<?php header("Content-Type:text/html; charset=utf-8");  
for($i=0; $i<35; $i++){     
if($i==0) $i = &#39;&#39;;    
 elseif($i<10) $i = &#39;0&#39;.$i;  
 $url = &#39;http://www.weather.com.cn/data/listinfo/city&#39;.$i.&#39;.xml&#39;; 
 $context = stream_context_create(     
 array(         
 &#39;http&#39; => array(            
  &#39;timeout&#39; => 3         
  )     
  ) ); 
  $xml = file_get_contents($url, false, $context);   
  $arr = explode(&#39;,&#39;, $xml); 
  $str = &#39;public static function city&#39;.$i.&#39;(){         
  return array(         &#39;; 
  foreach($arr as $val){     
  $prov = explode(&#39;|&#39;, $val);     
  $str .= "   &#39;".$prov[0]."&#39; => &#39;".$prov[1]."&#39;, "; }  
  print $str.&#39;        
   );     
   }         
    &#39;; }
Copy after login

 以上就是PHP城市级联|采集自中国天气网的内容,更多相关内容请关注PHP中文网(www.php.cn)!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template