How to use ctype_cntrl() function to check if all characters in a string are control characters (e.g. tab) in PHP

1 Answer

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

 



answered Mar 18, 2016 by avibootz
...