PHP String Tips: PHP have built in function name empty()for checking empty value. But, it is not good idea. Why? Because it will not work for variable have "0" value. PHP will treat "0" as false. So, it will return empty. But, we want "0" is exist, not empty. Solution?
We can use combination isset() and trim() function for checking. The code like this:
<?
$str = " ";
if(!isset($str) || trim($str) == ""){
echo "empty";
}else{
echo "not empty";
}
?>
The simple logic: use isset() to verify that exists, then use trim() function to trim whitespace from the edges.