php使用百度天气接口示例


Posted in PHP onApril 22, 2014

注意地区要转码的
百度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℃"
                }
            ]
        }
    ]
}
PHP 相关文章推荐
域名查询代码公布
Oct 09 PHP
phpmyadmin中配置文件现在需要绝密的短语密码的解决方法
Feb 11 PHP
php删除页面记录 同时刷新页面 删除条件用GET方式获得
Jan 10 PHP
解析PHPExcel使用的常用说明以及把PHPExcel整合进CI框架的介绍
Jun 24 PHP
解析PHP中的file_get_contents获取远程页面乱码的问题
Jun 25 PHP
PHP中模拟链表和链表的基本操作示例
Feb 27 PHP
thinkPHP3.2简单实现文件上传的方法
May 16 PHP
php简单实现单态设计模式的方法分析
Jul 28 PHP
详解php 使用Callable Closure强制指定回调类型
Oct 26 PHP
PHP获取文件扩展名的常用方法小结【五种方式】
Apr 27 PHP
PHP实时统计中文字数和区别
Feb 28 PHP
Laravel 实现数据软删除功能
Aug 21 PHP
phpmailer中文乱码问题的解决方法
Apr 22 #PHP
PHP函数addslashes和mysql_real_escape_string的区别
Apr 22 #PHP
自己写了一个php检测文件编码的函数
Apr 21 #PHP
CodeIgniter框架提示Disallowed Key Characters的解决办法
Apr 21 #PHP
PHP5中实现多态的两种方法实例分享
Apr 21 #PHP
PHP开发中常见的安全问题详解和解决方法(如Sql注入、CSRF、Xss、CC等)
Apr 21 #PHP
PHP正则提取不包含指定网址的图片地址的例子
Apr 21 #PHP
You might like
《雄兵连》系列首部大电影《烈阳天道》:可能是因为期望值太高了
2020/08/18 国漫
PHP下MAIL的另一解决方案
2006/10/09 PHP
PHP array操作10个小技巧分享
2011/06/23 PHP
php入门学习知识点三 PHP上传
2011/07/14 PHP
php读取excel文件的简单实例
2013/08/26 PHP
php数组去重实例及分析
2013/11/26 PHP
Codeigniter整合Tank Auth权限类库详解
2014/06/12 PHP
实现WordPress主题侧边栏切换功能的PHP脚本详解
2015/12/14 PHP
php结合redis高并发下发帖、发微博的实现方法
2016/12/15 PHP
PHP有序表查找之插值查找算法示例
2018/02/10 PHP
Laravel5框架添加自定义辅助函数的方法
2018/08/01 PHP
js 加载并解析XML字符串的代码
2009/12/13 Javascript
jQuery之日期选择器的深入解析
2013/06/19 Javascript
Javascript脚本实现静态网页加密实例代码
2013/11/05 Javascript
jquery提示效果实例分析
2014/11/25 Javascript
Nodejs实现的一个静态服务器实例
2014/12/06 NodeJs
js实现数组转换成json
2015/06/26 Javascript
pc加载更多功能和移动端下拉刷新加载数据
2016/11/07 Javascript
使用vue.js2.0 + ElementUI开发后台管理系统详细教程(二)
2017/01/21 Javascript
Javascript 链式作用域详细介绍
2017/02/23 Javascript
简单谈谈require模块化jquery和angular的问题
2017/06/23 jQuery
vue-test-utils初使用详解
2019/05/23 Javascript
JavaScript实现网页tab栏效果制作
2020/11/20 Javascript
[01:32]完美世界DOTA2联赛10月29日精彩集锦
2020/10/30 DOTA
Python 错误和异常小结
2013/10/09 Python
Python 编码Basic Auth使用方法简单实例
2017/05/25 Python
Python根据当前日期取去年同星期日期
2019/04/14 Python
python3实现小球转动抽奖小游戏
2020/04/15 Python
解决keras使用cov1D函数的输入问题
2020/06/29 Python
英国Radley包德国官网:Radley London德国
2019/11/18 全球购物
五星级酒店餐饮部总监的标准岗位职责
2014/02/17 职场文书
入学申请自荐信范文
2014/02/26 职场文书
员工考核评语大全
2014/04/26 职场文书
应届生求职自荐信范文
2015/03/04 职场文书
Python opencv缺陷检测的实现及问题解决
2021/04/24 Python
三种方式清除vue路由跳转router-link的历史记录
2022/04/10 Vue.js