Daniel Schierbeck wrote: > Chris Boget wrote: >> 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 > > $exceptions = array('the', , 'other', 'that', 'a'); > $string = 'The other lady that laughed'; > > foreach ($exsceptions as $exception) { > $string = str_replace(' ' . $exception . ' ', '', $string); > } This won't catch the words at the beginning or end of the string. Maybe use " $string " instead of just $string in the str_replace to cheat, and then http://php.net/trim it. Also, there's some kind of case-insensitive str_replace, but I never remember its name... RTFM. -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php