Are there any limitations or issues with using ord() function in PHP, especially with multibyte characters?
When using the ord() function in PHP with multibyte characters, there can be limitations or issues because ord() is intended for single-byte characters. To properly handle multibyte characters, you can use the mb_ord() function from the mbstring extension in PHP. This function specifically handles multibyte characters and returns the Unicode code point of the character.
function mb_ord($char, $encoding = 'UTF-8') {
$char = mb_convert_encoding($char, 'UCS-4BE', $encoding);
$code = unpack('N', $char);
return $code[1];
}
$multibyteChar = 'こんにちは';
$codePoint = mb_ord($multibyteChar);
echo $codePoint; // Output: 12371