This will be the fastest way:
$str = ' '; if (ctype_space($str)) { }
Returns false on an empty string because empty is not white space. If you need to include an empty string, you can add || $str == '' || $str == '' This will still lead to faster execution than regular expression or trimming.
ctype_space
webbiedave Jun 07 '10 at 19:16 2010-06-07 19:16
source share