zoukankan      html  css  js  c++  java
  • php xml转数组,数组转xml,array转xml,xml转array

    //数组转XML
        function arrayToXml($arr)
        {
            $xml = "<xml>";
            foreach ($arr as $key=>$val)
            {
                if (is_numeric($val)){
                    $xml.="<".$key.">".$val."</".$key.">";
                }else{
                     $xml.="<".$key."><![CDATA[".$val."]]></".$key.">";
                }
            }
            $xml.="</xml>";
            return $xml;
        }
    
        //将XML转为array
        function xmlToArray($xml)
        {    
            //禁止引用外部xml实体
            libxml_disable_entity_loader(true);
            $values = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);        
            return $values;
        }
    $money = 101;
    $sender = "方倍工作室";
    $obj2 = array();
    $obj2['wxappid']             = APPID;
    $obj2['mch_id']             = MCHID;
    $obj2['mch_billno']            = MCHID.date('YmdHis').rand(1000, 9999);
    $obj2['client_ip']            = $_SERVER['REMOTE_ADDR'];
    $obj2['re_openid']             = $openid;
    $obj2['total_amount']       = $money;
    $obj2['min_value']             = $money;
    $obj2['max_value']             = $money;
    $obj2['total_num']             = 1;
    $obj2['nick_name']          = $sender;
    $obj2['send_name']          = $sender;
    $obj2['wishing']            = "恭喜发财";
    $obj2['act_name']              = "方倍工作室送红包";
    $obj2['remark']              = "关注公众账号";
    <xml>
      <wxappid><![CDATA[wx1b7559b818e3c123]]></wxappid>
      <mch_id>1235571234</mch_id>
      <mch_billno>1235571234201605241726128109</mch_billno>
      <client_ip><![CDATA[127.0.0.1]]></client_ip>
      <re_openid><![CDATA[oiPuduGV7gJ_MOSfAWpVmhhgXh-U]]></re_openid>
      <total_amount>101</total_amount>
      <min_value>101</min_value>
      <max_value>101</max_value>
      <total_num>1</total_num>
      <nick_name><![CDATA[方倍工作室]]></nick_name>
      <send_name><![CDATA[方倍工作室]]></send_name>
      <wishing><![CDATA[恭喜发财]]></wishing>
      <act_name><![CDATA[方倍工作室送红包]]></act_name>
      <remark><![CDATA[关注公众账号]]></remark>
    </xml>
  • 相关阅读:
    tomcat7的catalina.sh配置说明
    nginx防攻击的简单配置
    linux系统自签发免费ssl证书,为nginx生成自签名ssl证书
    mysql ERROR 1045 (28000): Access denied for user 'root'@'localhost'
    /var/log/secure 文件清空
    Linux日志文件
    记一次网站被挂马处理
    Uedit32对文本进行回车换行
    安装mysql血泪史。
    mysql-8.0.19安装教程(Windows)
  • 原文地址:https://www.cnblogs.com/zonglonglong/p/8873338.html
Copyright © 2011-2022 走看看