Quickly master the skills of using PHP JSON encryption function_PHP tutorial

WBOY
Release: 2016-07-15 13:32:54
Original
788 people have browsed it

The following are specific applications of PHP JSON encryption functions:

  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. }  

希望通过上面这段代码的演示,大家能够充分掌握PHP JSON加密函数的用法,帮助自己完善代码编程。


www.bkjia.comtruehttp://www.bkjia.com/PHPjc/446100.htmlTechArticle以下为PHP JSON加密函数的具体应用: functionphp_json_encode($arr) { $ json_str = ; if(is_array($arr)) { $ pure_array = true ; $ array_length = count ($arr); for($ i = 0...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!