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. }  
  • 相关阅读:
    脑子好,蹦两下!程序员应该玩的小游戏
    推荐博客备份软件blog_bakcup
    经验(转)
    as super
    ActionScript工程如何使用Flash CS的fl包中的UI组件(转)
    astar(转)
    GROUPING,ROLLUP和CUBE(转)
    什么是分区表?为什么要用分区表?如何创建分区表?
    Flash player 详解(zhuan)
    jsfl(转)
  • 原文地址:https://www.cnblogs.com/zhouwenwu/p/2409268.html
Copyright © 2011-2022 走看看