: This article mainly introduces the open-source free weather forecast API and the code provided by the National Meteorological Administration of all regions of the country. if you are interested in PHP tutorials, please refer to it. Some articles on this site are translated from English documents, but my English level is limited. please forgive me if you have any statements. the Source of the translations is usually provided at the end of this article, for more information, see the original English version. In addition, some functions of this site are gradually being improved ......
Coming soon! If you have any questions, you can move to the feedback page!
The weather forecast has always been a basic function of major websites. Recently, I want to get a weather report from my website. I 've been searching for it on the Internet for a long time, finally, we found the open-source free weather forecast API and the code for all regions of the country (provided by the National Meteorological Administration). The details are as follows:
Weather forecast interface provided by the National Meteorological Administration
-Get provincial code: http://www.weather.com.cn/data/list3/city.xml? Level = 1
-
Get city code (for example, Anhui is 22): http://www.weather.com.cn/data/list3/city22.xml? Level = 2
-
Get the region code (for example, Anqing is 2206): http://www.weather.com.cn/data/list3/city2206.xml? Level = 3
The code obtained from Wangjiang county, Anqing city, Anhui province is 220607
-Then add the Chinese code request URL: http://m.weather.com.cn/data/101220607.html to get the local weather.
Header ("content-type: text/html; charset = utf-8"); $ weather = file_get_contents ("http://www.weather.com.cn/data/sk/101280601.html"); echo $ weather;
The above introduces the open-source free weather forecast API and the code provided by the National Meteorological Administration of all regions of the country, including the content, hope to be helpful to friends who are interested in PHP tutorials.