Php uses the Baidu weather interface example _ php instance

Source: Internet
Author: User
This article mainly introduces the use example of the Baidu weather interface. if you need a friend, refer to the region to be transcoded.
Baidu ak application address: http://lbsyun.baidu.com/apiconsole/key

The code is as follows:


$ City = "Jiaxing ";
$ Content = file_get_contents ("http://api.map.baidu.com/telematics/v3/weather? Location = % E5 % 98% 89% E5 % 85% B4 & output = json & ak = 5slgyqGDENN7Sy7pw29IUvrZ ");
Print_r (json_decode ($ content ));

The code is as follows:


{
Error: 0,
Status: "success ",
Date: "2014-04-18 ",
Results :[
{
CurrentCity: "Jiaxing ",
Weather_data :[
{
Date: "Today (Wednesday )",
DayPictureUrl: "http://api.map.baidu.com/images/weather/day/duoyun.png ",
NightPictureUrl: "http://api.map.baidu.com/images/weather/night/duoyun.png ",
Weather: "multi-cloud ",
Wind: "Breeze ",
Temperature: "23 ℃"
},
{
Date: "Tomorrow (Thursday )",
DayPictureUrl: "http://api.map.baidu.com/images/weather/day/leizhenyu.png ",
NightPictureUrl: "http://api.map.baidu.com/images/weather/night/zhongyu.png ",
Weather: "thundershower to moderate rain ",
Wind: "Breeze ",
Temperature: "29 ~ 22 ℃"
},
{
Date: "The Day After Tomorrow (Friday )",
DayPictureUrl: "http://api.map.baidu.com/images/weather/day/yin.png ",
NightPictureUrl: "http://api.map.baidu.com/images/weather/night/duoyun.png ",
Weather: "overcast to cloudy ",
Wind: "Breeze ",
Temperature: "31 ~ 23 ℃"
},
{
Date: "The Day After Tomorrow (Saturday )",
DayPictureUrl: "http://api.map.baidu.com/images/weather/day/duoyun.png ",
NightPictureUrl: "http://api.map.baidu.com/images/weather/night/duoyun.png ",
Weather: "multi-cloud ",
Wind: "Breeze ",
Temperature: "31 ~ 24 ℃"
}
]
},
{
CurrentCity: "Hefei ",
Weather_data :[
{
Date: "Today (Wednesday )",
DayPictureUrl: "http://api.map.baidu.com/images/weather/day/duoyun.png ",
NightPictureUrl: "http://api.map.baidu.com/images/weather/night/duoyun.png ",
Weather: "multi-cloud ",
Wind: "DongFeng 3-4 ",
Temperature: "27 ℃"
},
{
Date: "Tomorrow (Thursday )",
DayPictureUrl: "http://api.map.baidu.com/images/weather/day/duoyun.png ",
NightPictureUrl: "http://api.map.baidu.com/images/weather/night/duoyun.png ",
Weather: "multi-cloud ",
Wind: "Northeast wind 3-4 ",
Temperature: "35 ~ 27 ℃"
},
{
Date: "The Day After Tomorrow (Friday )",
DayPictureUrl: "http://api.map.baidu.com/images/weather/day/duoyun.png ",
NightPictureUrl: "http://api.map.baidu.com/images/weather/night/duoyun.png ",
Weather: "multi-cloud ",
Wind: "Nanfeng ",
Temperature: "35 ~ 27 ℃"
},
{
Date: "The Day After Tomorrow (Saturday )",
DayPictureUrl: "http://api.map.baidu.com/images/weather/day/duoyun.png ",
NightPictureUrl: "http://api.map.baidu.com/images/weather/night/duoyun.png ",
Weather: "multi-cloud ",
Wind: "Dongfeng ",
Temperature: "34 ~ 27 ℃"
}
]
}
]
}

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.