How to use ctype_space() function to check if all characters in a string are whitespace in PHP

1 Answer

0 votes
$arr = array("13.5\n", "abcXYZ", "AbCd1fgH7", "\n\r\t", '\n', "*$!()[]");
     
foreach ($arr as $s) 
{
    if (ctype_space($s)) 
        echo "$s is all whitespace characters <br />";
    else
        echo "$s is NOT all whitespace characters <br />";
}
     
/*
run:
   
13.5 is NOT all whitespace characters
abcXYZ is NOT all whitespace characters
AbCd1fgH7 is NOT all whitespace characters
is all whitespace characters
\n is NOT all whitespace characters
*$!()[] is NOT all whitespace characters 
      
*/
 

 



answered Mar 18, 2016 by avibootz
...