Re: Inconsistent behavior with preg_match_all in conditional

From: Date: Wed, 29 May 2002 04:30:59 +0000
Subject: Re: Inconsistent behavior with preg_match_all in conditional
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-99623@lists.php.net to get a copy of this message
On Wednesday 29 May 2002 11:06, Randy Janinda wrote: > Hello everyone, > > I have a script to check a user submitted string. It may be multiple > words. If a word is found to be 3 characters or less, the script should > retain the case of the string IF all the characters are uppercase. > Otherwise, the script will make the first character of each word > uppercase. So "Main st" becomes "Main St" and "Main st NB" > becomes "Main > St NB". Easy enough right? > > So take a look and let me know if this is a bug or feature. > > Here's the chunk of code and you can test it in action at > http://www.tqlabs.com/testcase.php (and .phps accordingly): > > if ($MyString) { > $safeInfo = explode(" ",strip_tags(stripslashes(trim($MyString)))); > foreach($safeInfo as $strTok) { > print "Checking: $strTok<BR>"; > if (strlen($strTok) <= 3) { > $case = preg_match_all("/[A-Z]/",$strTok,$junk); > $count = strlen($strTok); > > /////////////////////////////////////// > // Why won't this work?!?!?! > /////////////////////////////////////// > if (preg_match_all("[A-Z]",$strTok,$junk) == strlen($strTok)) { Is this a typo? Shouldn't it be the same as above with the '/' delimiters?

« previous php.general (#99623) next »