How to use ctype_graph() function to check if all characters in a string are printable (visible - not space) in PHP

1 Answer

0 votes
$arr = array('13.5\n', 'abcXYZ', 'AbCd1fgH7', 'xyz@!$wsp', '   ');
     
foreach ($arr as $s) 
{
    if (ctype_graph($s)) 
        echo "$s is printable characters <br />";
    else
        echo "$s is NOT printable characters <br />";
}
     
/*
run:
   
13.5\n is printable characters
abcXYZ is printable characters
AbCd1fgH7 is printable characters
xyz@!$wsp is printable characters
is NOT printable characters 
      
*/

 



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