How can I check whether a character is a Unicode character or not with PHP?
is_utf8() – check for UTF-8 With this PHP function it's possible to check whether a string is encoded as UTF-8 or not, or seems to be, at least. It scans a string for invalid UTF-8 characters (or bytes) and returns false, if it finds any.
PHP does not offer native Unicode support. PHP only supports a 256-character set. However, PHP provides the UTF-8 functions utf8_encode() and utf8_decode() to provide some basic Unicode functionality. See the PHP manual for strings for more details about PHP and Unicode.
To insert a Unicode character, type the character code, press ALT, and then press X. For example, to type a dollar symbol ($), type 0024, press ALT, and then press X.
In PHP, mb_detect_encoding() is used to detect the character encoding. It can detect the character encoding for a string from an ordered list of candidates. This function is supported in PHP 4.0. 6 or higher version.
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];
you can try with
mb_check_encoding($s,"UTF-8")
link
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With