最好用的XML转换成数组方法

来源:https://www.sucaihuo.com/php/938.html 2016-08-28 23:01浏览(1244) 收藏

以微信推送海关为例的xml为例,xml在线转换数组,再复杂的xml结构,用这个简单xml转换数组方法即可展现数组结构。
最好用的XML转换成数组方法
分类:PHP > 函数 难易:入门级
下载资源 下载积分: 20 积分

xml代码

以微信海关推送代码为例:https://pay.weixin.qq.com/wiki/doc/api/external/declarecustom.php?chapter=18_1

$xml = "<xml>
   <appid>wx2421b1c4370ec43b</appid>
   <customs>ZHENGZHOU_BS</customs>
   <mch_customs_no>D00411</mch_customs_no>
   <mch_id>1262544101</mch_id>
   <order_fee>13110</order_fee>
   <out_trade_no>15112496832609</out_trade_no>
   <product_fee>13110</product_fee>
   <sign>8FF6CEF879FB9555CD580222E671E9D4</sign>
   <transaction_id>1006930610201511241751403478</transaction_id>
   <transport_fee>0</transport_fee>
   <fee_type>CNY</fee_type>
   <sub_order_no>15112496832609001</sub_order_no>
</xml>";
function xmlToArray2($xml) {
    // 将XML转为array
    $array_data = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
    return $array_data;
}

xml转换成数组后:

print_r(xmlToArray2($xml));
标签: 数组分布产品
评论0
头像

系统已开启自动识别垃圾评论机制,识别到的自动封号,下载出错或者资源有问题请联系全栈客服QQ 1915635791

1 2