You have your answer, just use this:

$outstring = eregi_replace("badword","goodword",$stringtocheck);

It'll replace it whether it's at the beginning or end of a string, embedded
in a word, or by itself. Isn't that what you want?

Actually, it'd be better and faster to just use str_replace() instead of a
regular expression...

---John Holmes...

----- Original Message -----
From: "John S. Huggins" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, June 14, 2002 11:37 AM
Subject: [PHP] Beginning /< and end of word /> in eregi_replace


>
> Can it be true that PHP does not implement the beginning and end of word
> syntax of regular expressions?
>
> In builing a bad word filter, I find this...
>
>   $outstring = eregi_replace("badword$","goodword",$stringtocheck);
>
> will find an occurance of the 'badword' at the end of the string and
> replace it.
>
> Similarly,
>
>   $outstring = eregi_replace("^badword","goodword",$stringtocheck);
>
> will find an occurance of the 'badword' at the beginning of the string
> and replace it.
>
> Also,
>
>   $outstring = eregi_replace("badword","goodword",$stringtocheck);
>
> will find all occurances of 'badword' even if they are part of a longer
> not so bad word like 'badwordage' and replace it.
>
> Then,
>
>   $outstring = eregi_replace(" badword ","goodword",$stringtocheck);
>
> will help me isolate just the actual bad word, but not those at the
> beginning and end of a string or that end in a period or comma.
>
> So I could make a rule for each possible placement of badword in a string
> and then do this for each vulger term I try to filter.  Or I could just
> do...
>
>   $outstring = eregi_replace("/<badword/>","goodword",$stringtocheck);
>
> Which should find any occurance of 'badword' and nothing more anywhere in
> the string.  It works in grep.  It works in bash.  It does not seem to
> work in PHP.
>
> Anybody know what I might be doing wrong?
>
> **************************************
>
> John Huggins
> VANet
>
> [EMAIL PROTECTED]
> http://www.va.net/
>
> **************************************
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to