How do I detect non-ASCII characters in a string?
I found it more useful to detect if any character falls out of the list
if(preg_match('/[^\x20-\x7e]/', $string))
Try (mb_detect_encoding)
You can use mb_detect_encoding
and check for ASCII:
mb_detect_encoding($str, 'ASCII', true)
This will return false if $str
contains at least one non-ASCI character (byte value > 0x7F).