Re: Pattern Matching

From: Date: Fri, 23 May 2003 16:57:52 +0000
Subject: Re: Pattern Matching
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-148801@lists.php.net to get a copy of this message
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/ > >

« previous php.general (#148801) next »