Unicode surrogate pairs

…衆ロ難τιáo~ 提交于 2019-12-22 00:53:56

问题


Say I have a surrogate pair. For example:

\u306f\u30fc

Is there a function I can use to print the character to the screen?


回答1:


If you want to do it manually:

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

If you have the string, you could always do:

$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);

Or, if 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);


来源:https://stackoverflow.com/questions/3506120/unicode-surrogate-pairs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!