加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

读取xml格式的天气预报的代码

发布时间:2020-12-16 02:14:37 所属栏目:百科 来源:网络整理
导读:读取xml格式的天气预报的代码 ?php$apistr=file_get_contents("http://api.map.baidu.com/telematics/v2/weather?location=%E4%B8%8A%E6%B5%B7ak=B8aced94da0b345579f481a1294c9094"); //获取xml内容$apiobj=simplexml_load_string($apistr);//解析xml代码$t

读取xml格式的天气预报的代码

<?php
$apistr=file_get_contents("http://api.map.baidu.com/telematics/v2/weather?location=%E4%B8%8A%E6%B5%B7&ak=B8aced94da0b345579f481a1294c9094"); //获取xml内容
$apiobj=simplexml_load_string($apistr);//解析xml代码
$todayobj=$apiobj->results->result[0]->date;//读取星期
$weatherobj=$apiobj->results->result[0]->weather;//读取天气
$windobj=$apiobj->results->result[0]->wind;//读取风力
$temobj=$apiobj->results->result[0]->temperature;//读取温度
$contentStr = "上海n{$todayobj}n天气:{$weatherobj}n风力:{$windobj}n温度:{$temobj}";
echo $contentStr;
?>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读