How to use ctype_space() to checks if all of the characters in a string is whitespace characters in PHP

1 Answer

0 votes
$str = array("\n\r\t", '\n\r\t', 'abc\n', 'xyz', '  ');
foreach ($str as $s) 
{
    if (ctype_space($s)) 
        echo "string: $s - include only whitespace characters <br />";
    else 
        echo "string: $s - NOT include only whitespace characters <br />";
}


/*
run: 

string: - include only whitespace characters
string: \n\r\t - NOT include only whitespace characters
string: abc\n - NOT include only whitespace characters
string: xyz - NOT include only whitespace characters
string: - include only whitespace characters 

*/

 



answered Jun 7, 2016 by avibootz
...