3

在 C++ 中,可以使用这种表示法创建一个 UTF-8 字符串:"\uD840\uDC50".

但是,这在 PHP 中不起作用。有没有类似的符号?

如果没有,是否有任何内置方法可以创建知道其 Unicode 代码点的 UTF-8 字符串?

4

2 回答 2

9

我最终像这样实现它:

$utf8 = html_entity_decode("一", ENT_COMPAT, 'UTF-8');
于 2013-04-19T06:57:41.363 回答
2
function hexToString($str){return chr(hexdec(substr($str, 2)));}
$result = preg_replace_callback("/(\\\\x..)/isU", function($m) { return hexToString($m[0] ); }, $str);
于 2015-02-23T10:29:13.023 回答