detecting blank field

A

Anonymous

Guest
What is the best way to check if a field is blank? For instance I want to print out addresses to the screen, but don't want a blank line if there is nothing on address line 2.

This is what I have now:

echo"$first_name $last_name<br>";
if ($address != '') echo"$address<br>";
if ($address2 != '') echo"$address2<br>";
if ($city != '') echo"$city,";
if ($state !='') echo" $state $zip<br>";

This doesn't seem to be working quite right, I suspect that there are some spaces in the fields.

TIA,
Fred
 
if($yourVar) echo "This variable is not empty.";

or you can use the empty() function :wink:
 
you can use the combination of
emtpy() strlen() < 0 ,isset() :arrow:
 
Back
Top