将XML存储在Array中


store XML in Array

这是我想将XML转换为数组的链接
http://services.gisgraphy.com/geoloc/search?lat=22.298569900000000000&lng=70.794301799999970000&radius=7000
点击上面的链接它会返回一个XML文件
我想把它存储在数组
中请帮助……
谢谢

只是一个小提示…转换为数组很容易,如强制转换(array)

$xml = file_get_contents('http://services.gisgraphy.com/geoloc/search?lat=22.298569900000000000&lng=70.794301799999970000&radius=7000', true);
$xml = (array)simplexml_load_string($xml);
print_r($xml);

您可以使用php中的simplexml_load_string

:

<?php
$string = <<<XML
<?xml version='1.0'?> 
<document>
 <title>Forty What?</title>
 <from>Joe</from>
 <to>Jane</to>
 <body>
  I know that's the answer -- but what's the question?
 </body>
</document>
XML;
$xml = simplexml_load_string($string);
print_r($xml);
?>

SimpleXMLElement Object
(
  [title] => Forty What?
  [from] => Joe
  [to] => Jane
  [body] =>
   I know that's the answer -- but what's the question?
)

阅读http://php.net/manual/en/function.simplexml-load-string.php获取更多信息。

也可以使用https://github.com/gaarf/XML-string-to-PHP-array/blob/master/xmlstr_to_array.php

您必须获取它并将其转换为简单的xml对象。

$responce = file_get_contents('http://services.gisgraphy.com/geoloc/search?lat=22.298569900000000000&lng=70.794301799999970000&radius=7000', true); print_r(simplexml_load_string($responce));