GBK的页面输出JSON格式的php函数

前端之家收集整理的这篇文章主要介绍了GBK的页面输出JSON格式的php函数前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

<div class="codetitle"><a style="CURSOR: pointer" data="47935" class="copybut" id="copybut47935" onclick="doCopy('code47935')"> 代码如下:

<div class="codebody" id="code47935">
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,$to);
}
return $m;
case ‘array':
foreach($m as $k => $v) {
$m[tb_json_convert_encoding($k,$to)] = tb_json_convert_encoding($v,$to);
}
return $m;
default:
}
return $m;
}

猜你在找的PHP相关文章