Php xml Conversion Array
From: http://hi.baidu.com/wfyuck/item/b9fd62d74cc83be254347f2f
$ Info = '<? Xml version = "1.0" encoding = "UTF-8"?>
<Data>
<GeocoderSearchResponse>
<Status> OK </status>
<Result>
<Location>
<Lat> 39.94921 </lat>
<Lng> 116.463619 </lng>
</Location>
<Precise> 0 </precise>
<Confidence> 50 </confidence>
<Level> Road </level>
</Result>
</GeocoderSearchResponse>
<GeocoderSearchResponse>
<Status> OK </status>
<Result>
<Location>
<Lat> 39 </LAT>
<LNG> 116 </LNG>
</Location>
<Precise> 0 </precise>
<Confidence> 50 </confidence>
<Level> road 123 </level>
</Result>
</Geocodersearchresponse>
</Data> ';
$ Xml = simplexml_load_string ($ info );
Function xml2array ($ xmlobject ){
If ($ xmlobject ){
Foreach (array) $ xmlobject as $ k => $ v ){
$ Data [$ k] =! Is_string ($ v )? Xml2array ($ v): $ v;
}
Return $ data;
}
}
$ Data = xml2array ($ xml );
Result:
Array (1) {["GeocoderSearchResponse"] = & gt; array (2) {[0] => array (2) {["status"] = & gt; string (2) "OK" ["result"] = & gt; array (4) {["location"] = & gt; array (2) {["lat"] = & gt; string (8) "39.94921" ["lng"] = & gt; string (10) "116.463619"} ["precise"] = & gt; string (1) "0" ["confidence"] = & gt; string (2) "50" ["level"] => string (6) "road"} [1] => array (2) {["status"] = & gt; string (2) "OK" ["result"] = & gt; array (4) {["location"] = & gt; array (2) {["lat"] = & gt; string (2) "39" ["lng"] = & gt; string (3) "116"} ["precise"] = & gt; string (1) "0" ["confidence"] = & gt; string (2) "50" ["level"] => string (9) "road 123 "}}}}