How to check if a string is in specific ASCII range with PHP

1 Answer

0 votes
function check_characters($str) {
    for ($i = 0; $i < strlen($str); $i++) {
    	if (!(ord($str[$i]) >= 32 && ord($str[$i]) <= 57)) {
    		return false;
    	}
    }
    
    return true;
}

$str = "(+)!-127.847 +$84925 %";

echo check_characters($str) ? "yes" : "no";





/*
run:

yes

*/

 



answered May 27, 2022 by avibootz
...