php将数组转换为JSON中文字符串(兼容中文)

详细查看:https://blog.lmlyz.online/index/detail/id/84.html

使用json_encode将PHP数组转为json格式时编码问题,以下函数将其转为中文:

function json_encode_cn($array, $force_object=false) {
    if ($force_object) {
        return unicodeDecode(json_encode($array, JSON_FORCE_OBJECT));
    }
    return unicodeDecode(json_encode($array));
}
function unicodeDecode($data) {           
    $rs = preg_replace_callback('/\\\\u([0-9a-f]{4})/i', 'replace_unicode_escape_sequence', $data);    
    return $rs;
}

你可能感兴趣的:(PHP,php,json,字符串)