手机
当前位置:查字典教程网 >编程开发 >php教程 >GBK的页面输出JSON格式的php函数
GBK的页面输出JSON格式的php函数
摘要:复制代码代码如下:functiontb_json_encode($value,$options=0){returnjson_encode(t...

复制代码 代码如下:

function tb_json_encode($value, $options = 0)

{

return json_encode(tb_json_convert_encoding($value, “GBK”, “UTF-8″));

}

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

{

return tb_json_convert_encoding(json_decode($str, $assoc), “UTF-8″, “GBK”);

}

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

{

switch(gettype($m)) {

case ‘integer':

case ‘boolean':

case ‘float':

case ‘double':

case ‘NULL':

return $m;

case 'string':

return mb_convert_encoding($m, $to, $from);

case ‘object':

$vars = array_keys(get_object_vars($m));

foreach($vars as $key) {

$m->$key = tb_json_convert_encoding($m->$key, $from ,$to);

}

return $m;

case ‘array':

foreach($m as $k => $v) {

$m[tb_json_convert_encoding($k, $from, $to)] = tb_json_convert_encoding($v, $from, $to);

}

return $m;

default:

}

return $m;

}

【GBK的页面输出JSON格式的php函数】相关文章:

GD输出汉字的函数的分析

php页面缓存ob系列函数介绍

编写自己的php扩展函数

PHP的开合式多级菜单程序

模拟xcopy的函数

如何使用动态共享对象的模式来安装PHP

php使用for语句输出三角形的方法

PHP实现的增强性mhash函数

php生成随机密码的自定义函数

php格式化电话号码的方法

精品推荐
分类导航