Re: [PHP] Replacing whole words only

2004-12-22 Thread David OBrien
I'm also an idiot ... Something else, the "or" output is occurring because the exception "the" matches "other " first so "other" becomes "or" minus the "the"... So heres what I did ... $search = array( '/\bthe\b/', '/\bother\b/', '/\bthat\b/', '/\ba\b/' ); $string = 'The other lady that laughed'

Re: [PHP] Replacing whole words only

2004-12-22 Thread John Holmes
> From: "Chris Boget" <[EMAIL PROTECTED]> > Is there a way to replace/remove *whole* words from a > phrase? For example: [snip] > $stringToParse = str_replace( $exceptionPhrase, '', trim( > $stringToParse )); Try this instead of str_replace() $stringToParse = preg_replace("/(^|\\W){$exce

Re: [PHP] Replacing whole words only

2004-12-22 Thread Chris Boget
> The case is what's stopping it from working > a str_replace(strtolower($exceptionphrase) , '' , > strtolower($stringtoparse)) would take the case out of the equation No, that didn't entire quite work, either. The result from this change is "or ldy lughed" and not the desired result of "lady la

Re: [PHP] Replacing whole words only

2004-12-22 Thread David OBrien
uot; <[EMAIL PROTECTED]> > Date: 2004/12/22 Wed AM 10:27:50 EST > To: "PHP General" > Subject: [PHP] Replacing whole words only > > Is there a way to replace/remove *whole* words from a > phrase? For example: > >$exceptionsList = array( 'the

[PHP] Replacing whole words only

2004-12-22 Thread Chris Boget
Is there a way to replace/remove *whole* words from a phrase? For example: 0 ) { foreach( $exceptionsList as $exceptionPhrase ) { $stringToParse = str_replace( $exceptionPhrase, '', trim( $stringToParse )); } $retval = trim( $stringToParse ); } echo 'Retval: ' . $retval .