I'm trying to detect if a Unicode string is printable.
For example, I have a user who has set their name to %EF%B8%8F
- which is variation selector-16 (U+FE0F)
I want to be able to do something like
if ($screen_name == null || $screen_name == NotPrintable )
{
...Show an error...
} else {
...Proceed as normal...
}
Is there any way to detect if a Unicode string is printable?
Users names can be any valid Unicode sequence (English, Chinese, Arabic, etc).
Some previous answers suggest complex regexes which look like they only work with a narrow range of characters.
I've tried counting the length of the string, but that doesn't work -
$odd = urldecode("%EF%B8%8F");
print strlen($odd);
3
Same result for mb_strlen()
as well.
Functions like ctype_print()
won't work because regular strings can contain non-printable characters.
So, is there any way to detect whether a Unicode string will display printable characters?