How to use ctype_alnum() function to check if all characters in a string are alphanumeric (letters and/or digits) in PHP

1 Answer

0 votes
$arr = array('abcXYZ', 'AbCd1fgH7', 'xyz@!$wsp', '123');
    
foreach ($arr as $s) 
{
    if (ctype_alnum($s)) 
        echo "$s is letters and/or digits <br />";
    else
        echo "$s is NOT just letters and/or digits <br />";
}
    
/*
run:
  
abcXYZ is letters and/or digits
AbCd1fgH7 is letters and/or digits
xyz@!$wsp is NOT just letters and/or digits
123 is letters and/or digits  
     
*/

 



answered Mar 18, 2016 by avibootz
edited Mar 18, 2016 by avibootz
...