This article mainly introduces the method of implementing XML transform array in PHP, and analyzes the operation skill of PHP operation XML format file to transform array with concrete instance form, involving the method of loading, traversing and transforming XML format data, and the need of friends can refer to
Specific as follows:
<?php$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</pre cise> <confidence>50</confidence> <level> Scripts </level> </result> </GeocoderSearchResponse> <GeocoderSearchResponse> <status>OK</status> <result> <location> <lat>39</lat> <LNG>116</LNG > </location> <precise>0</precise> <CONFIDENCE>50</CONFIDENCE&G T <level> script 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); Var_dump ($data);? >
The results of the operation are as follows:
Array (1) {["Geocodersearchresponse"]=> Array (2) { [0]=> Array (2) { ["status"]=> string (2) "OK" ["Result"]=> Array (4) { ["location"]=> Array (2) { ["lat"]=> string (8) " 39.94921 " [" LNG "]=> string (Ten)" 116.463619 " } [" Precise "]=> string (1)" 0 " [" Confidence "]=> string (2)" ["Level"]=> string (6) "script"} } [1]=> Array (2) { ["status"]=> string (2) "OK" ["Result"]=> Array (4) { ["location"]=> Array (2) { ["lat"]=> string (2) "["] ["LNG"]=> string (3) " " " Precise "]=> string (1)" 0 " [" Confidence "]=> string (2)" " [" Level "]=> string (9 ) "Script 123"}}}
The above is the whole content of this article, I hope that everyone's study has helped.