Check unicode in PHP

前端 未结 6 520
予麋鹿
予麋鹿 2020-12-28 17:36

How can I check whether a character is a Unicode character or not with PHP?

6条回答
  •  温柔的废话
    2020-12-28 18:10

    Actually you don't even need the mb_string extension:

    if (strlen($string) != strlen(utf8_decode($string)))
    {
        echo 'is unicode';
    }
    

    And to find the code point of a given character:

    $ord = unpack('N', mb_convert_encoding($string, 'UCS-4BE', 'UTF-8'));
    
    echo $ord[1];
    

提交回复
热议问题