0

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

4

3 回答 3

2

你可以simplexml_load_string使用php

例如:_

<?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

于 2013-03-23T08:15:37.143 回答
2

只是一个小提示..转换为数组很容易,就像强制转换 (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);
于 2013-03-23T08:32:28.050 回答
1

您必须获取它,然后转换为简单的 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));

于 2013-03-23T08:16:08.717 回答