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

读取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;
?>

相关文章

php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念