RE: [PHP] Pattern Matching

From: Date: Fri, 23 May 2003 19:11:43 +0000
Subject: RE: [PHP] Pattern Matching
Groups: php.general 
Request: Send a blank email to php-general+get-148804@lists.php.net to get a copy of this message
Notice the difference between empty() and IsSet() : http://il.php.net/manual/en/function.empty.php $var = 0; if (empty($var)) { // evaluates true echo '$var is either 0 or not set at all'; } if (!isset($var)) { // evaluates false echo '$var is not set at all'; } Sincerely berber Visit http://www.weberdev.com/ Today!!! To see where PHP might take you tomorrow. -----Original Message----- From: Daniel J. Rychlik [mailto:drychlik@tcsconsult.com] Sent: Friday, May 23, 2003 6:58 PM To: holmes072000@charter.net; php-general@lists.php.net Subject: Re: [PHP] Pattern Matching Yea, this is great! Thank so much. Ive still got a lot of reading to do by way of new functions. ----- Original Message ----- From: "John W. Holmes" <holmes072000@charter.net> To: "'Daniel J. Rychlik'" <drychlik@tcsconsult.com>; <php-general@lists.php.net> Sent: Friday, May 23, 2003 11:54 AM Subject: RE: [PHP] Pattern Matching > > Difficult to learn new tricks when you're used to doing something > > one > way, > > but im applying my mind. Never the less, > > > > Im trying to pattern match to find empty fields. > > > > Im using the ereg() function. In perl, you just call it. > > > > snipit > > if ( ereg ( " ", $value)) { > > > > echo "'$key' Missing input "; > > } > > > > The results : returns false every time. Except for the Submit > button, > > then it returns true *sigh*.... > > > > I know that it has to do with what Im searching for and that is > basically > > just a " " <- blank space. > > Why not just use empty()? > > foreach($_POST as $key=>$value) > { > if(empty($value)) > { echo "$key: Missing Input"; } > } > > Don't use regular expressions when you don't have to. Yes, they are > nice and very useful, but you'll be surprised that a lot of the time > having more code and using simple string functions will be faster than > a regex one-liner. Always benchmark your code. > > As for your problem, I suspect it's because you're searching for a > space instead of an empty string. "" vs. " ". An empty form field is > going to be "" (for text fields) or not even set if it's a > checkbox/radio button. > > > Hope that helps. > > ---John W. Holmes... > > PHP Architect - A monthly magazine for PHP Professionals. Get your > copy today. http://www.phparch.com/ > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.general (#148804) next »