zoukankan      html  css  js  c++  java
  • php的json加密函数(php5.2以上免)

    1. function php_json_encode($arr)  
    2. {  
    3.     $json_str = "";  
    4.     if(is_array($arr))  
    5.     {  
    6.       $pure_array = true;  
    7.       $array_length = count($arr);  
    8.       for($i=0;$i<$array_length;$i++)  
    9.       {  
    10.         if(! isset($arr[$i]))  
    11.         {  
    12.           $pure_array = false;  
    13.           break;  
    14.         }  
    15.       }  
    16.       if($pure_array)  
    17.       {  
    18.         $json_str ="[";  
    19.         $temp = array();  
    20.         for($i=0;$i<$array_length;$i++)         
    21.         {  
    22.           $temp[] = sprintf("%s", php_json_encode($arr[$i]));  
    23.         }  
    24.         $json_str .= implode(",",$temp);  
    25.         $json_str .="]";  
    26.       }  
    27.       else  
    28.       {  
    29.         $json_str ="{";  
    30.         $temp = array();  
    31.         foreach($arr as $key => $value)  
    32.         {  
    33.           $temp[] = sprintf("/"%s/":%s"$key, php_json_encode($value));  
    34.         }  
    35.         $json_str .= implode(",",$temp);  
    36.         $json_str .="}";  
    37.       }  
    38.     }  
    39.     else  
    40.     {  
    41.       if(is_string($arr))  
    42.       {  
    43.         $json_str = "/"". json_encode_string($arr) . "/"";  
    44.       }  
    45.       else if(is_numeric($arr))  
    46.       {  
    47.         $json_str = $arr;  
    48.       }  
    49.       else  
    50.       {  
    51.         $json_str = "/"". json_encode_string($arr) . "/"";  
    52.       }  
    53.     }  
    54.     return $json_str;  
    55. }  
  • 相关阅读:
    【Python应用:基于PyQt5文本识别】调用百度AI对一张或多张图片、文件夹中的图片和屏幕区域截图进行识别(PDF转Word 小意思)
    【Ubuntu搭建Django编程环境】:创建python虚拟开发环境和配置pip国内镜像源
    23种设计模式上篇
    荷兰国旗问题
    文件复制多份
    mybatis批量更新
    数组小和
    常见排序算法
    福尔摩斯的约会
    小明上学
  • 原文地址:https://www.cnblogs.com/zhouwenwu/p/2409268.html
Copyright © 2011-2022 走看看