Unicode代理对

时间:2010-08-17 19:21:52

标签: php unicode surrogate-pairs

说我有一个代理对。例如:

\u306f\u30fc

是否有可用于将角色打印到屏幕的功能?

1 个答案:

答案 0 :(得分:2)

如果您想手动执行此操作:

echo chr(0x30) . chr(0x6f) . chr(0x30) . chr(0xfc);

如果您有字符串,您可以随时执行:

$callback = function($match) { 
    return chr(hexdec($match[1])) . chr(hexdec($match[2]));
}
preg_replace_callback('#\\\\u([0-9a-f]{2})([0-9a-f]{2})#', $callback, $string);

或者,如果php< 5.3

$callback = create_function('$match', 
    'return chr(hexdec($match[1])) . chr(hexdec($match[2]));'
);
preg_replace_callback('#\\\\u([0-9a-f]{2})([0-9a-f]{2})#', $callback, $string);