xml转换成数组的问题
现有如下xml:
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --> <root> <rows> <errMsg text=""/> <retValue text="true"/> </rows> <records> <productno text="000321"/> <billno text=""/> <orderno text="D004410439"/> <out_trade_no text="100001"/> <plcprem text="0.0"/> <orderprem text="50.0"/> <commision text="0.0"/> </records> .... <root>
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->
Array
(
[rows] => Array
(
[errMsg] =>
[retValue] => true
)
[records] => Array
(
[productno] =>000321
[billno] =>
[orderno] =>D004410439
[out_trade_no] => 100001
[plcprem] =>0.0
[orderprem] =>50.0
[commision] =>0.0
)
.....
)
$s =
<rows><errmsg text=""></errmsg><retvalue text="true"></retvalue></rows><records><productno text="000321"></productno><billno text=""></billno><orderno text="D004410439"></orderno><out_trade_no text="100001"></out_trade_no><plcprem text="0.0"></plcprem><orderprem text="50.0"></orderprem><commision text="0.0"></commision></records>
XML;
$obj = simplexml_load_string($s);
$r = array();
foreach($obj as $name=>$nodes) {
foreach($nodes as $k=>$v) {
$t = (array)$v->attributes()->text;
$r[$name][$k] = $t[0];
}
}
print_r($r);
<br><font color="#e78608">------解决方案--------------------</font><br>
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号