function isSpace(?string $a): bool { if ($a == null) return true; if ($a == '') return true; return preg_match('/^\s*$/', $a) == 1; } function hasContent(?string $a): bool { return ! isSpace($a); }
Programming Tips - PHP: a robust way to check a string for being empty
Date: 2016nov15
Language: php
Q. PHP: a robust way to check a string for being empty
A. These functions handle undefined, null, zero length and ignore leading and trailing space