In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the relevant knowledge of "how to collect weather forecast information from the whole country by php". In the operation of actual cases, many people will encounter such a dilemma. Then let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Weather forecast information collected from the Central Meteorological Station, accurate information, wide coverage, simple code, the return is json code, can be used for client-side calls, can also be displayed after server-side processing, the author's wordpress weather forecast plug-in is the use of this code, it should be noted that this code will generate cache files in the server, need to create a new data folder in the current directory to ensure that the folder can be written.
The php weather forecast code is as follows:
The copy code is as follows:
/ *
Author: freemouse
Home page: www.cnphp.info
API demo: http://www.cnphp.info/tianqi
Usage: you can directly call the above address to display the local weather information, or you can use it this way.
Http://www.cnphp.info/tianqi/?q= Nanjing, 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" > "Xizang"
"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) {
If (! file_exists (". / data/city {$key} .xml") {
C = file_get_contents ("http://m.weather.com.cn/data5/city{$key}.xml")
File_put_contents (". / data/city {$key} .xml", $c)
}
Else {
C = file_get_contents (". / data/city {$key} .xml")
}
$arr = explode (",", $c)
Foreach ($arr as $v) {
$data = explode ("|", $v)
$ret [$data [0]] = $data [1]
}
Return $ret
}
Array_walk ($pendant arr.findcards, etc.)
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");"
This is the end of the content of "how to collect Weather Forecast Information from the whole country by php". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.