如何在php中将xml转换为数组? [英] How to convert xml into array in php?
本文介绍了如何在php中将xml转换为数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将下面的XML转换为PHP数组.关于如何执行此操作的任何建议?
I want to convert below XML to PHP array. Any suggestions on how I can do this?
<aaaa Version="1.0">
<bbb>
<cccc>
<dddd Id="id:pass" />
<eeee name="hearaman" age="24" />
</cccc>
</bbb>
</aaaa>
推荐答案
另一种选择是SimpleXML扩展(我相信大多数PHP安装中它都是标准配置.)
Another option is the SimpleXML extension (I believe it comes standard with most php installs.)
http://php.net/manual/zh/book.simplexml.php
对于您的示例,语法看起来像这样
The syntax looks something like this for your example
$xml = new SimpleXMLElement($xmlString);
echo $xml->bbb->cccc->dddd['Id'];
echo $xml->bbb->cccc->eeee['name'];
// or...........
foreach ($xml->bbb->cccc as $element) {
foreach($element as $key => $val) {
echo "{$key}: {$val}";
}
}
这篇关于如何在php中将xml转换为数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文