Php uses the Baidu weather interface example. Note: The baidu ak application address for transcoding in the region is lbsyun. baidu. comapiconsolekey. the code for copying the key is as follows :? Php $ city Jiaxing; $ contentfile_get_contents (api. map. Note that the region must 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 ℃"
}
]
}
]
}
Baidu ak application address: http://lbsyun.baidu.com/apiconsole/key code is as follows :? Php $ city = "Jiaxing"; $ content = file_get_contents ("http://api.map ....