本文介绍了PHP Unicode代码点到字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将Unicode代码点转换为字符.这是我尝试过的:
I would like to convert Unicode codepoint to character. Here is what I have tried:
$point = dechex(127468); // 1f1ec
echo "\u{1f1ec}"; // this works
echo "\u{$point}"; // this outputs '\u1f1ec'
echo "\u{{$point}}"; // Parse error: Invalid UTF-8 codepoint escape sequence
echo "\u\{{$point}\}"; // outputs \u\{1f1ec\}
echo "\u{". $point ."}"; // Parse error; same as above
推荐答案
您不需要将整数转换为十六进制字符串,而是使用 IntlChar :: chr :
You don't need to convert integer to hexadecimal string, instead use IntlChar::chr:
echo IntlChar::chr(127468);
直接来自IntlChar::chr
的文档:
这篇关于PHP Unicode代码点到字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!