grapheme_strlen() returns null or false on failure, including
when the input is not valid UTF-8.
Use intl_get_error_code() and intl_error_name()
to retrieve the ICU error details.
<?php
$string = "\xFF"; // invalid UTF-8 byte sequence
$length = grapheme_strlen($string);
if (!is_int($length)) {
$code = intl_get_error_code();
printf("grapheme_strlen() failed: %s (%d)\n", intl_error_name($code), $code);
} else {
echo $length, PHP_EOL;
}
?>
The above example will output:
grapheme_strlen() failed: U_INVALID_CHAR_FOUND (10)