PHP Unicode代码点到字符

jak*_*_jo 4 php unicode

我想将Unicode代码点转换为字符.这是我尝试过的:

$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
Run Code Online (Sandbox Code Playgroud)

Ani*_*wat 5

您不需要将整数转换为十六进制字符串,而是使用IntlChar :: chr:

echo IntlChar::chr(127468);
Run Code Online (Sandbox Code Playgroud)

直接来自以下的文档IntlChar::chr:

按代码点值返回Unicode字符

  • 凉豆.我必须给这个书签,因为我相信我以后会遇到这个问题然后去"又是什么呢?" :) (2认同)