note 78596 deleted from function.empty by didou

From: Date: Sun, 18 May 2008 00:54:19 +0000
Subject: note 78596 deleted from function.empty by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-139473@lists.php.net to get a copy of this message
Note Submitter: BigBadaboom ---- If you are writing a form handling script and just need to check whether a required field has been filled in, you can just use strlen() to check the field. It handles all the cases properly when you are only dealing with strings. $x = "0"; echo strlen($x); // returns 1 $x = ""; echo strlen($x); // returns 0 unset $x echo strlen($x); // returns 0 In other words, the check you need to make becomes: if (strlen($email) == 0) $error = "Please enter your email address"; or if (strlen($_POST["email"]) == 0) $error = "Please enter your email address"; Hopes this helps anyone just seeking a workaround for the annoying empty("0") anomaly.

« previous php.notes (#139473) next »