note 24398 added to function.empty

From: Date: Thu, 15 Aug 2002 09:58:27 +0000
Subject: note 24398 added to function.empty
Groups: php.notes 
Request: Send a blank email to php-notes+get-35057@lists.php.net to get a copy of this message
Don't confuse about this function and try yourself to understand how to finding the contents of a field from php by this simple code that compare empty function with !isset / =="" / ==null / ==none and strlen()==0 (PHP Version 4.2.2) //////// emptytest.php ///////// <? echo "\$foo=$foo"." [ "; //Standard if (!empty($foo)) echo " <font color='blue'>!empty</font> / "; if (empty($foo)) echo " <font color='red'>empty</font> / "; // Compare with isset function if (isset($foo)) echo " <font color='blue'>isset</font> / "; if (!isset($foo)) echo " <font color='red'>!isset</font> / "; // Compare with =="" or =='' if ($foo!="") echo " <font color='blue'>!=&quot;&quot;</font> / "; if ($foo=="") echo "<font color='red'>==&quot;&quot;</font> / "; // Compare with null if ($foo!=null) echo " <font color='blue'>not null</font> / "; if ($foo==null) echo " <font color='red'>null</font> / "; // Compare with none if ($foo!=none) echo " <font color='blue'>not none</font> / "; if ($foo==none) echo " <font color='red'>none</font> / "; // Use strlen($foo) function echo "AND string length="; if(strlen($foo)!=0) echo " <font color='blue'>".strlen($foo); else echo "<font color='red'>0"; echo "</font> ] \n"; ?><form name="form1" method="post" action=""> <input type="text" name="foo"><input type="submit" name="Submit" value="Submit"> <input type="reset" name="Reset" value="Reset"> </form> //////// end code ///////// When you try mysample value the result show this. First start code in new windows browser $foo= [ empty / !isset / =="" / null / not none / AND string length=0 ] Submit with or without focus in field or reset form $foo= [ empty / isset / =="" / null / not none / AND string length=0 ] Submit with zero $foo=0 [ empty / isset / !="" / not null / not none / AND string length= 1 ] Submit with 00 $foo=00 [ !empty / isset / !="" / not null / not none / AND string length= 2 ] Submit with null $foo=null [ !empty / isset / !="" / not null / not none / AND string length= 4 ] Submit with none $foo=none [ !empty / isset / !="" / not null / none / AND string length= 4 ] Submit with pao $foo=pao [ !empty / isset / !="" / not null / not none / AND string length= 3 ] Submit with " " $foo= [ !empty / isset / !="" / not null / not none / AND string length= 1 ] Submit with " " $foo= [ !empty / isset / !="" / not null / not none / AND string length= 2 ] -- http://www.php.net/manual/en/function.empty.php http://master.php.net/manage/user-notes.php?action=edit+24398 http://master.php.net/manage/user-notes.php?action=delete+24398 http://master.php.net/manage/user-notes.php?action=reject+24398

« previous php.notes (#35057) next »