PHP Unicode codepoint to character

前端 未结 3 1957
轻奢々
轻奢々 2020-12-17 03:23

I would like to convert Unicode codepoint to character. Here is what I have tried:

$point = dechex(127468);  // 1f1ec

echo \"\\u{1f1ec}\";         // this w         


        
相关标签:
3条回答
  • 2020-12-17 03:53

    You don't need to convert integer to hexadecimal string, instead use IntlChar::chr:

    echo IntlChar::chr(127468);
    

    Directly from docs of IntlChar::chr:

    Return Unicode character by code point value

    0 讨论(0)
  • 2020-12-17 03:54

    Actually find the solution after several hours:

    $unicode = '1F605'; //                                                                    
    0 讨论(0)
  • 2020-12-17 03:56

    A similar problem occurs when you want to get a floating point number, say, 12e-4, concatenating pieces. The parsing is done too early in the compiler to allow it. You probably can, however, use eval() to do so. Yuck.

    0 讨论(0)
提交回复
热议问题