Re: Replacing whole words only

From: Date: Wed, 22 Dec 2004 15:42:15 +0000
Subject: Re: Replacing whole words only
Groups: php.general 
Request: Send a blank email to php-general+get-204962@lists.php.net to get a copy of this message
The case is what's stopping it from working a str_replace(strtolower($exceptionphrase) , '' , strtolower($stringtoparse)) would take the case out of the equation and for php5 theres always the case insensitive version str_ireplace() -David > > From: "Chris Boget" <chris.boget@wild.net> > Date: 2004/12/22 Wed AM 10:27:50 EST > To: "PHP General" <php-general@lists.php.net> > Subject: [PHP] Replacing whole words only > > Is there a way to replace/remove *whole* words from a > phrase? For example: > > <? > $exceptionsList = array( 'the', 'other', 'that', 'a' > ); > $stringToParse = 'The other lady that laughed'; > > if( count( $exceptionsList ) > 0 ) { > foreach( $exceptionsList as $exceptionPhrase ) { > $stringToParse = str_replace( $exceptionPhrase, '', trim( > $stringToParse )); > > } > $retval = trim( $stringToParse ); > > } > echo 'Retval: ' . $retval . '<br>'; > ?> > > results in "The or ldy lughed" and not "lady laughed". Using > the other *_replace() functions give the same results. So is > what I'm looking to do even possible? > > thnx, > Chris > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >

« previous php.general (#204962) next »