从SimpleXMLElement对象获取值我有这样的事情:$url = "http://ws.geonames.org/findNearbyPostalCodes?country=pl&placename=";$url .= rawurlencode($city[$i]);$xml = simplexml_load_file($url);echo $url."\n";$cityCode[] = array(
'city' => $city[$i],
'lat' => $xml->code[0]->lat,
'lng' => $xml->code[0]->lng);它应该从geonames下载XML。如果我这样做,print_r($xml)我得到:SimpleXMLElement Object(
[code] => Array
(
[0] => SimpleXMLElement Object
(
[postalcode] => 01-935
[name] => Warszawa
[countryCode] => PL [lat] => 52.25
[lng] => 21.0
[adminCode1] => SimpleXMLElement Object
(
)
[adminName1] => Mazowieckie
[adminCode2] => SimpleXMLElement Object
(
)
[adminName2] => Warszawa
[adminCode3] => SimpleXMLElement Object
(
)
[adminName3] => SimpleXMLElement Object
(
)
[distance] => 0.0
)我可以看到$xml->code[0]->lat,它会返回一个对象。我怎样才能获得价值?
- 3 回答
- 0 关注
- 1054 浏览
添加回答
举报
0/150
提交
取消