您好,欢迎访问一九零五行业门户网

php对xml的操作十分简单,

php对xml的操作非常简单,急急急
http://api.map.baidu.com/telematics/v3/weather?location=北京&output=xml&ak=gfpnxaaipynihm7c3ez1kmel
这个得到xml 如何把currentcity节点的值赋给$city,循环检索weather_data下的所有节点,赋值给数组 -》$date ,给$daypictureurl。
------解决方案--------------------
$url = 'http://api.map.baidu.com/telematics/v3/weather?location=北京&output=xml&ak=gfpnxaaipynihm7c3ez1kmel';
$xml = simplexml_load_file($url);
echo $city = $xml->xpath('//currentcity')[0];
foreach($xml->xpath('//weather_data') as $r) {
$date = (array)$r->date;
$daypictureurl = (array)$r->daypictureurl;
}
var_dump($city, $date, $daypictureurl);
北京object(simplexmlelement)#2 (0) {
}
array(4) {
[0]=>
string(30) 周五(今天, 实时:24℃)
[1]=>
string(6) 周六
[2]=>
string(6) 周日
[3]=>
string(6) 周一
}
array(4) {
[0]=>
string(57) http://api.map.baidu.com/images/weather/day/leizhenyu.png
[1]=>
string(51) http://api.map.baidu.com/images/weather/day/yin.png
[2]=>
string(52) http://api.map.baidu.com/images/weather/day/qing.png
[3]=>
string(52) http://api.map.baidu.com/images/weather/day/qing.png
}

其它类似信息

推荐信息