Home  >  Article  >  Backend Development  >  Open source free weather forecast interface API and provided by the National Meteorological Administration for all regional codes in the country

Open source free weather forecast interface API and provided by the National Meteorological Administration for all regional codes in the country

WBOY
WBOYOriginal
2016-08-08 09:22:111312browse

Some articles on this site are translated from English documents, but due to my limited English proficiency, please forgive me for any incomprehensible sentences. The source of the translation is usually given at the end of the article. Those who are good at English can refer to the original English version. In addition, some functions of this site are being gradually improved...
Please stay tuned! If you have any questions, you can leave a message for feedback!
Weather forecast has always been a basic function of major websites. Recently, the editor also wanted to have one on the website. After searching on the Internet for a long time, I finally found the open source free weather forecast interface API and all regional codes in the country ( Provided by the National Meteorological Administration), the details are as follows:
Weather forecast interface provided by the National Meteorological Administration
- Get the provincial code: http://www.weather.com.cn/data/list3/city.xml?level=1
-
Get the city code (for example, Anhui is 22): http://www.weather.com.cn/data/list3/city22.xml?level=2
-
Get the area code (for example, Anqing is 2206): http:/ /www.weather.com.cn/data/list3/city2206.xml?level=3
Get the code of Wangjiang County, Anqing City, Anhui Province, which is 220607

- Then add the Chinese code to request the 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 has introduced the open source free weather forecast interface API and all regional codes in the country provided by the National Meteorological Administration, including relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
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
Previous article:php get pathNext article:php get path