Home > Backend Development > PHP Tutorial > PHP weather forecast code collected from the Central Meteorological Observatory covering the whole country_PHP tutorial

PHP weather forecast code collected from the Central Meteorological Observatory covering the whole country_PHP tutorial

WBOY
Release: 2016-07-20 11:08:43
Original
1091 people have browsed it

PHP weather forecast code is collected from the Central Meteorological Observatory and covers the whole country. The weather forecast information is collected from the Central Meteorological Observatory. The information is accurate, the coverage is wide, and the code is simple. The return is json code, which can be used for client calls or displayed after processing on the server side. This code is used by the author's WordPress weather forecast plug-in. It should be noted that this code will generate a cache file on the server. You need to create a new data folder in the current directory to ensure that the folder is writable

PHP tutorial weather forecast code is collected from the Central Meteorological Observatory and covers the whole country
Weather Forecast The information is collected from the Central Meteorological Observatory, the information is accurate, the coverage is wide, and the code is simple. The return is json code, which can be used for client calls or displayed after processing on the server side. This code is used by the author's WordPress weather forecast plug-in. It should be noted that this code will generate cache files on the server. You need to create a new data folder in the current directory to ensure that the folder is writable

Author: freemouse
Home page: www.cnphp.info
Interface demo: http://www.cnphp.info/tianqi
Usage: You can directly call the above address to display local weather information, or you can use it like this
http:/ /www.cnphp.info/tianqi/?q=Nanjing City, Jiangsu Province
**/

$p = $_get['q'];
$k = 0;
$encoding = mb_detect_encoding($p);
if($encoding != "utf-8"){
        $p = mb_convert_encoding($p,"utf-8", "gbk");
     }
      $p_arr = array(
      "01" => "Beijing",
"02" => "Shanghai",
"03" => "Tianjin",
"04" => "Chongqing",
"05" => "Heilongjiang",
"06" => "Jilin",
"07" => "Liaoning",
"08" => "Inner Mongolia",
"09" => "Hebei" ,
"10" => "Shanxi",
"11" => "Shaanxi",
"12" => "Shandong",
"13" => " "Xinjiang",
"14" => "Tibet",
"15" => "Qinghai",
"16" => "Gansu",
"17" => "Ningxia",
"18" => "Henan",
"19" => "Jiangsu",
"20" => "Hubei",
"21" => "Zhejiang",
"22" => "Anhui",
"23" => "Fujian",
"24" => "Jiangxi",
" 25" => "Hunan",
"26" => "Guizhou",
"27" => "Sichuan",
"28" => "Guangdong",
"29" => "Yunnan",
"30" => "Guangxi",
"31" => "Hainan",
"32" => "Hong Kong",
"33" => "Macau",
"34" => "Taiwan"
);

function find(&$item,$key,$data){
global $k;
if(preg_match("/$item/u",$data)){
$k = $key;
}
}

function get_data_arr($key){
                                                                                                                                                                               cn/data5/city{$key}.xml" );
                            file_put_contents("("./data/city{$key}.xml",$c); c = file_get_contents("./data/city{$key}.xml");
    }
      $arr = explode(",",$c);  
                                                     {
             $data = explode("|",$v);                                                     }

array_walk($p_arr,'find',$p);
array_walk(get_data_arr($k),'find',$p);
array_walk(get_data_arr($k), 'find',$p);
$ccode = get_data_arr($k);
echo file_get_contents("http://m.weather.com.cn/data/{$ccode[$k]}.html");


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/444854.htmlTechArticlephp The weather forecast code is collected from the Central Meteorological Observatory and covers the whole country. The weather forecast information is collected from the Central Meteorological Observatory. The information is accurate and has wide coverage. , the code is simple. The return is json code, you can...
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template