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.


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

will find an occurance of the 'badword' at the beginning of the string
and replace it.


  $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.


  $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

  $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



PHP General Mailing List (
To unsubscribe, visit:

Reply via email to