Home > Backend Development > PHP Tutorial > GBK page output JSON php code

GBK page output JSON php code

WBOY
Release: 2016-07-25 09:02:46
Original
1007 people have browsed it
  1. function tb_json_encode($value, $options = 0)

  2. {
  3. return json_encode(tb_json_convert_encoding($value, “GBK”, “UTF-8″));
  4. }

  5. function tb_json_decode($str, $assoc = false, $depth = 512)

  6. {
  7. return tb_json_convert_encoding(json_decode($str, $assoc), “UTF-8″, “GBK”);
  8. }

  9. function tb_json_convert_encoding($m, $from, $to)

  10. {
  11. switch(gettype($m)) {
  12. case ‘integer’:
  13. case ‘boolean’:
  14. case ‘float’:
  15. case ‘double’:
  16. case ‘NULL’:
  17. return $m;

  18. case ’string’:

  19. return mb_convert_encoding($m, $to, $from);
  20. case ‘object’:
  21. $vars = array_keys(get_object_vars($m));
  22. foreach($vars as $key) {
  23. $m->$key = tb_json_convert_encoding($m->$key, $from ,$to);
  24. }
  25. return $m;
  26. case ‘array’:
  27. foreach($m as $k => $v) {
  28. $m[tb_json_convert_encoding($k, $from, $to)] = tb_json_convert_encoding($v, $from, $to);
  29. }
  30. return $m;
  31. default:
  32. }
  33. return $m;
  34. }
  35. ?>

复制代码


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