Php capture weather forecast interface data problems, ask for advice National Meteorological Administration free weather forecast interface (Shenyang): http://www.weather.com.cn/data/cityinfo/101010100.html
This interface provides a weather forecast data in json format.
I don't know how to get this json using php. I found the following code on the Internet:
However, the httpGetRequest function is a custom function, and the prototype of this function is not released online! Please kindly advise!
Reply to discussion (solution)
$url = 'http://www.weather.com.cn/data/cityinfo/101070101.html';$s = file_get_contents($url);print_r(json_decode($s, true));
Array
(
[Weatherinfo] => Array
(
[City] => Shenyang
[Cityid] = & gt; 101070101
[Temp1] => 10 ℃
[Temp2] =>-2 ℃
[Weather] => multi-cloud
[Img1] => d1.gif
[Img2] => n1.gif
[Ptime] => 08:00
)
)
HttpGetRequest does not need to be ignored. The purpose is to capture the text. it is just a means. you can write it by yourself.
Directly obtain the file_get_contents from the moderator. to save traffic, use curl or socket to send a compression request.
Use file_get_contents to complete the work, and wait for time to learn about curl, socket... and then optimize it.
In the code you paste, $ info is the data you get.
The moderator is the moderator. thank you very much! I would also like to thank snmr_com for its optimization suggestions!
The moderator is correct...
This interface is no longer updated and the retrieved data is incorrect.
Http://club.weather.com.cn/thread-555402-1-1.html