Http://api.map.baidu.com/telematics/v3/weather?location= Beijing &output=xml&ak=gfpnxaaipynihm7c3ez1kmel
This gets how XML assigns the value of the CurrentCity node to $city, loops through all the nodes under the Weather_data, assigns the value to the array -"$date, To $daypictureurl.
Reply to discussion (solution)
Where is the great God?
$url = ' http://api.map.baidu.com/telematics/v3/weather?location= Beijing &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);
Beijing object (simplexmlelement) #2 (0) {}array (4) { [0]=> string (30) "Friday (Today, Live: 24 ℃)" [1]=> string ( 6) "Saturday" [2]=> string (6) "Sunday" [3]=> string (6) "Monday"}array (4) { [0]=> string (57) " Http://api.map.baidu.com/images/weather/day/leizhenyu.png " [1]=> string"/http Api.map.baidu.com/images/weather/day/yin.png " [2]=> string" http://api.map.baidu.com/images/ Weather/day/qing.png " [3]=> string" Http://api.map.baidu.com/images/weather/day/qing.png "}
$url = ' http://api.map.baidu.com/telematics/v3/weather?location= Beijing &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);
Beijing object (simplexmlelement) #2 (0) {}array (4) { [0]=> string (30) "Friday (Today, Live: 24 ℃)" [1]=> string ( 6) "Saturday" [2]=> string (6) "Sunday" [3]=> string (6) "Monday"}array (4) { [0]=> string (57) " Http://api.map.baidu.com/images/weather/day/leizhenyu.png " [1]=> string"/http Api.map.baidu.com/images/weather/day/yin.png " [2]=> string" http://api.map.baidu.com/images/ Weather/day/qing.png " [3]=> string" Http://api.map.baidu.com/images/weather/day/qing.png "}
Parse error:syntax error, unexpected ' [', expecting ', ' or '; '
My code is verified by the test!
Or you can't put the results.
My code is verified by the test!
Or you can't put the results.
Don't be angry, my side is this mistake ah, seems to be the parentheses have problems
My code is verified by the test!
Or you can't put the results.
OK, seemingly to separate write can not directly echo $city = $xml->xpath ('//currentcity ') [0];
Can do this
$city = $xml->xpath ('//currentcity ');
echo $city [0];
That's your problem.
Besides, the error message has to be affixed to the whole, otherwise how others judge the problem?
I think it's your PHP version that's too low.
$city = $xml->xpath ('//currentcity ') [0];
Switch
$city = current ($xml->xpath ('//currentcity '));
That's your problem.
Besides, the error message has to be affixed to the whole, otherwise how others judge the problem?
I think it's your PHP version that's too low.
$city = $xml->xpath ('//currentcity ') [0];
Switch
$city = current ($xml->xpath ('//currentcity '));
Rookie totally not Ah, also please moderator forgive me ah
foreach ($xml->xpath ('//weather_data ') as $r) {$date = (array) $r->date;print_r ($date);}
If it's written like this, why only one row of data Beijing
2014-04-25
Array ([0] = Friday (today, Real time: 24 ℃))
It's supposed to be Saturday and Sunday.