detecting blank field

Codes here !

Moderators: egami, macek, gesf

Post Reply
fredws
New php-forum User
New php-forum User
Posts: 14
Joined: Wed Jul 16, 2003 4:16 pm

Mon Sep 22, 2003 6:12 pm

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
liquedus
php-forum GURU
php-forum GURU
Posts: 264
Joined: Tue Apr 08, 2003 5:18 am
Location: Ottawa, Canada
Contact:

Mon Sep 22, 2003 6:48 pm

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

or you can use the empty() function :wink:
fredws
New php-forum User
New php-forum User
Posts: 14
Joined: Wed Jul 16, 2003 4:16 pm

Mon Sep 22, 2003 7:35 pm

That was what I was after!
Thanks liquedus!
sigix
php-forum GURU
php-forum GURU
Posts: 364
Joined: Mon Jul 14, 2003 9:39 pm
Location: /Earth/Xion

Tue Sep 23, 2003 8:07 am

you can use the combination of
emtpy() strlen() < 0 ,isset() :arrow:
something strange will be ...
Post Reply