This article describes how to use PHP to obtain the weather instance code of a specified region. For more information about how to use PHP to obtain the weather instance code of a specified region, see the following article, for more information, see
PHP obtains weather conditions in a specified region.
Weather query is used when developing a website. because it is based on Wordpress, there are many restrictions. First, create a [weather. PHP] file and check the code:
Weatherinfo-> city. ':'. $ obj-> weatherinfo-> weather1. '. $ obj-> weatherinfo-> temp1;
For:
$ Url = 'http: // m.weather.com.cn/data/'; $ id = '000000'; // Jiaozuo code $ data = file_get_contents ($ url. $ id .'.html ');
Can be abbreviated:
$data = file_get_contents('http://m.weather.com.cn/data/101181101.html');
For:
$obj=json_decode($data);
It converts the obtained json data into an object for convenient calling;
Then the last sentence:
echo $obj->weatherinfo->city.':'.$obj->weatherinfo->weather1.' '.$obj->weatherinfo->temp1;
Is to obtain the specified data and output it in a certain format,
$ Obj-> weatherinfo-> city // city $ obj-> weatherinfo-> weather1 // today's weather $ obj-> weatherinfo-> temp1 // today's temperature
Finally
You can.
Thank you for reading this article. I hope it will help you. thank you for your support for this site!
For more PHP articles about getting the weather instance code for a specified region, please refer to PHP!