PHP 获取指定地区的天气实例代码
发布时间:2020-12-12 22:00:04 所属栏目:PHP教程 来源:网络整理
导读:PHP 获取指定地区的天气 在开发网站的时候用到天气查询,由于是基于Wordpress的 所以有很多限制,先建一个【weather.PHP】的文件,然后看代码: $obj=json_decode($data); echo $obj-weatherinfo-city.':'.$obj-weatherinfo-weather1.' '.$obj-weatherinfo-
PHP 获取指定地区的天气在开发网站的时候用到天气查询,由于是基于Wordpress的 所以有很多限制,先建一个【weather.PHP】的文件,然后看代码: $obj=json_decode($data);
echo $obj->weatherinfo->city.':'.$obj->weatherinfo->weather1.' '.$obj->weatherinfo->temp1; 对于: 可简写为: 而对于: 它是把获取的json数据转化为一个对象,方便调用; 那么最后一句: weatherinfo->city.':'.$obj->weatherinfo->weather1.' '.$obj->weatherinfo->temp1;
就是获取指定的数据并按照一定格式输出, weatherinfo->city //城市
$obj->weatherinfo->weather1 //今天的天气
$obj->weatherinfo->temp1 //今天的气温
最后 在需要显示的地方 即可。 感谢阅读,希望能帮助到大家,谢谢大家对本站的支持! (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- php – 如何在$_POST []中使用变量
- zend-framework – 如何将ZF2与Doctrine Mongo ODM集成?
- php utf-8转换gb2312 字符串被截断解决方法
- php实现Linux服务器木马排查及加固功能
- cakephp – acos表中使用的型号,lft和rght字段是什么?
- 使用php+apc实现上传进度条且在IE7下不显示的问题解决方法
- php – 如何将Google Analytics代码添加到Drupal 7
- php中对静态变量的初始化
- composer-php – yii2 composer update error:无效的版本字
- php – GAE本地开发环境是否包含memcache服务?