This will be the fastest way:
$str = ' ';
if (ctype_space($str)) {
}
Returns false on empty string because empty is not white-space. If you need to include an empty string, you can add || $str == ''
This will still result in faster execution than regex or trim.
ctype_space