Re: Replacing whole words only
| From: | John Holmes | Date: | Wed, 22 Dec 2004 15:55:30 +0000 |
| Subject: | Re: Replacing whole words only | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-204965@lists.php.net to get a copy of this message | ||
> From: "Chris Boget" <chris.boget@wild.net>
> 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){$exceptionPhrase}(\\W|$)/i",'\\1',$stringToParse);
---John Holmes...
UCCASS - PHP Survey System
http://www.bigredspark.com/survey.html