PHP obtains the weather instance code of a specified region.

Source: Internet
Author: User
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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.