How to detect if there is non-ASCII characters in a string with PHP

1 Answer

0 votes
$str = "PHP Java C C++ À È Ì Ò";

$result = preg_match('/[^\x20-\x7e]/', $str);

echo mb_detect_encoding($str, 'ASCII', true) ? "all ASCII" : "there is non-ASCII";






/*
run:

there is non-ASCII

*/

 



answered May 27, 2022 by avibootz

Related questions

...