PHP json_encode 保留中文

0
1
2
3
4
5
6
7
8
function json_encode_chinese($data) {
	if(version_compare(PHP_VERSION, '5.4.0', '>='))
		return json_encode($data, JSON_UNESCAPED_UNICODE);
 
	$code = PATH_SEPARATOR != ';' ? 'UCS-2BE' : 'UCS-2';
	$data = json_encode($data);
	return preg_replace("/\\\u([0-9a-f]{4})/ie", "iconv('$code', 'UTF-8', pack('H*', '$1'));", $data);
}

发表评论

您的邮箱不会公开,当您的评论有新的回复时,会通过您填写的邮箱向您发送评论内容。 必填字段 *

为何看不到我发布的评论?

正在提交, 请稍候...