<?php
header('Content-type:text/html;charset=utf-8');
function getChinese($code)
{
return preg_replace_callback('/\\\\u([0-9a-f]{4})/i',
create_function(
'$matches',
'return mb_convert_encoding(pack("H*", $matches[1]), "UTF-8", "UCS-2BE");'
),
$code);
}
$con= "\u7b7e\u540d\u9519\u8bef";
echo getChinese($con);echo "\n";
本文介绍了一段 PHP 代码,该代码实现了将特殊格式的 Unicode 编码转换为 UTF-8 编码的字符串。通过使用正则表达式和 mb_convert_encoding 函数,这段代码能够正确解析并显示中文字符。
1731

被折叠的 条评论
为什么被折叠?



