zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    测试是否有必要看开发代码?如何能看懂?
    【LeetCode】111. 二叉树的最小深度(BFS 解题套路框架,要会默写)
    【LeetCode】112. 路径总和
    【测试开发】知识点配置 Nginx 解决多端口访问
    【测试开发】知识点使用EasyExcel,实现excel导出和导入
    p5 随机圆连接背景和代码树
    angular技巧
    javascript原生技巧篇
    MybatisPlus
    安装 jupyter notebook
  • 原文地址:https://www.cnblogs.com/wuheng1991/p/5823200.html
Copyright © 2011-2022 走看看