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
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" <[EMAIL PROTECTED]> > Date: 20