from: stack overflow
If you want to boost, do it on another answer , not this one!
This will be the fastest way:
$str = ' '; if (ctype_space($str)) { }
Returns false on an empty string because empty is not empty. 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
as a function:
function stringIsNullOrWhitespace($text){ return ctype_space($text) || $text === "" || $text === null; }
David Murdoch Jun 19 '13 at 17:53 on 2013-06-19 17:53
source share