• XML转换成数组方法


    <?php
    
    
    
    function xmlToArray2($xml) {
        // 将XML转为array
        $array_data = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
        return $array_data;
    }
    
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
        <head> 
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
            <title>演示:最好用的XML转换成数组方法</title>
            <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
            <link rel="stylesheet" type="text/css" href="http://www.sucaihuo.com/jquery/css/common.css" />
            <style type="text/css">
            </style>
        </head>
        <body>
            <div style="500px;margin:30px auto 0;font-size: 16px;">
                <p class="notice">提示:以微信推送海关为例的xml为例,xml在线转换数组</p>
                <pre>
                <?php
                $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>";
                var_dump(xmlToArray2($xml));
                ?>
                </pre>
            </div>
        </body>
    </html>
    <!-- 以下是统计及其他信息,与演示无关,不必理会 -->
    
     
    <style type="text/css">
        .vad { margin: 250px 0 5px; font-family: Consolas,arial,宋体,sans-serif; text-align:center;}
        .vad a { display: inline-block; height: 36px; line-height: 36px; margin: 0 5px; padding: 0 50px; font-size: 14px;
    text-align:center; color:#eee; text-decoration: none; background-color: #222;} .vad a:hover { color: #fff; background-color: #000;} .thead { 728px; height: 90px; margin: 0 auto; border-bottom: 40px solid #fff;} </style>
  • 相关阅读:
    Akka-CQRS(4)- CQRS Writer Actor 示范
    Akka-CQRS(3)- 再想多点,全面点
    变量、作用域
    JSON概述
    js浮点精度问题
    自定义级联下拉框
    nodejs+express+mysql 增删改查(二)
    使用Navicat Premium 链接本地数据库的方法(二)
    行内编辑时间框
    thinkjs升级到3.0后的图片上传
  • 原文地址:https://www.cnblogs.com/wuheng1991/p/5823200.html
Copyright © 2020-2023  润新知