• 0

[PHP] Word Censoring Help


Question

Hello.

I am working and a function that censors words and I have come across a problem. In my little program, if some one types in the work "arse", it's replaced with asterisks. It words well, accepted when the word "arse" appear in another word like "rehearsed". It seems that when you type in "rehearsed" "rehe****d" is returned. Clearly this is not what I want

Here is my code:

$str = eregi_replace("arse","<B>****</B>",$str);

Can anyone advise how to avoid this problem?

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

in PREG you could just to "\Warse\W"

The \W's are just any non-word character (anythign that's not a letter, digit or underscore. Be sure to use the case insensitive modifier too :)

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.