程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> php使用百度天氣接口示例

php使用百度天氣接口示例

編輯:關於PHP編程

注意地區要轉碼的
百度ak申請地址:http://lbsyun.baidu.com/apiconsole/key

復制代碼 代碼如下:
<?php

$city="嘉興";
$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));

復制代碼 代碼如下:
{
    error: 0,
    status: "success",
    date: "2014-04-18",
    results: [
        {
            currentCity: "嘉興",
            weather_data: [
                {
                    date: "今天(周三)",
                    dayPictureUrl: "http://api.map.baidu.com/images/weather/day/duoyun.png",
                    nightPictureUrl: "http://api.map.baidu.com/images/weather/night/duoyun.png",
                    weather: "多雲",
                    wind: "微風",
                    temperature: "23℃"
                },
                {
                    date: "明天(周四)",
                    dayPictureUrl: "http://api.map.baidu.com/images/weather/day/leizhenyu.png",
                    nightPictureUrl: "http://api.map.baidu.com/images/weather/night/zhongyu.png",
                    weather: "雷陣雨轉中雨",
                    wind: "微風",
                    temperature: "29~22℃"
                },
                {
                    date: "後天(周五)",
                    dayPictureUrl: "http://api.map.baidu.com/images/weather/day/yin.png",
                    nightPictureUrl: "http://api.map.baidu.com/images/weather/night/duoyun.png",
                    weather: "陰轉多雲",
                    wind: "微風",
                    temperature: "31~23℃"
                },
                {
                    date: "大後天(周六)",
                    dayPictureUrl: "http://api.map.baidu.com/images/weather/day/duoyun.png",
                    nightPictureUrl: "http://api.map.baidu.com/images/weather/night/duoyun.png",
                    weather: "多雲",
                    wind: "微風",
                    temperature: "31~24℃"
                }
            ]
        },
        {
            currentCity: "合肥市",
            weather_data: [
                {
                    date: "今天(周三)",
                    dayPictureUrl: "http://api.map.baidu.com/images/weather/day/duoyun.png",
                    nightPictureUrl: "http://api.map.baidu.com/images/weather/night/duoyun.png",
                    weather: "多雲",
                    wind: "東風3-4級",
                    temperature: "27℃"
                },
                {
                    date: "明天(周四)",
                    dayPictureUrl: "http://api.map.baidu.com/images/weather/day/duoyun.png",
                    nightPictureUrl: "http://api.map.baidu.com/images/weather/night/duoyun.png",
                    weather: "多雲",
                    wind: "東北風3-4級",
                    temperature: "35~27℃"
                },
                {
                    date: "後天(周五)",
                    dayPictureUrl: "http://api.map.baidu.com/images/weather/day/duoyun.png",
                    nightPictureUrl: "http://api.map.baidu.com/images/weather/night/duoyun.png",
                    weather: "多雲",
                    wind: "南風",
                    temperature: "35~27℃"
                },
                {
                    date: "大後天(周六)",
                    dayPictureUrl: "http://api.map.baidu.com/images/weather/day/duoyun.png",
                    nightPictureUrl: "http://api.map.baidu.com/images/weather/night/duoyun.png",
                    weather: "多雲",
                    wind: "東風",
                    temperature: "34~27℃"
                }
            ]
        }
    ]
}

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved