zoukankan      html  css  js  c++  java
  • 03 xml封装通信接口

    <?php
    
    class Response_xml{
    
      /**
      *按xml方式输出通信
      *@param integet $code 状态码
      *@param string $message 提示信息
      *@param array $data 数据
      * return string
      */
      public static function xml_encoding($code,$message,$data=array()){
            
               if(is_null($code)){
                return '';
               }
               $result=array(
                'code'=>$code,
                'message'=>$message,
                'data'=>$data
               );
              header("Content-Type:text/xml");
             $xml ="<?xml version='1.0' encoding='UTF-8'?>
    ";
             $xml.="<root>
    ";
             $xml.=self::xml_array($result);
             $xml.="</root>
    ";
             echo $xml;
    
        }
        public static function xml_array($result){
            $xml=$attr="";
            foreach ($result as $key => $value) {
                if(is_numeric($key)){
                   $attr=" id='{$key}'";
                   $key="item";
                }
                $xml.="<{$key}{$attr}>
    ";
                $xml.=is_array($value)?self::xml_array($value):$value;
                $xml.="</{$key}>
    ";
            }
            return $xml;
        }
    
    }
       $data=array(
        'id'=>1,
        'name'=>'hgj123',
       );
       $data1=array(1,2,3,11,122);
    Response_xml::xml_encoding(200,'数据返回成功',$data1);
  • 相关阅读:
    data-icon=""图片还可以是自定义的?
    orientationchange不管用啊
    menu({postion:{my:"left top"},at:"right bottom"})里的my与at会冲突吗
    关于position的疑惑
    Linux
    C++
    MATLAB
    SCE
    SFLA混合蛙跳算法
    memetic algorithm
  • 原文地址:https://www.cnblogs.com/hgj123/p/4353860.html
Copyright © 2011-2022 走看看