The following script will take your variable $comments and filter out any bad words. eregi_replace is case-insensitive, so it will take out the word, no matter the way it is input.

$bad_words = explode('|', 'badword1|badword2|badword3|etc|etc');
   foreach ($bad_words as $naughty)
   {
      $comments = eregi_replace($naughty, "#!@%*#", $comments);
   }

This will turn the input "I really think that you are a badword1, and a badword2"

into

"I really think that you are a #!@%*#, and a #!@%*#"

It will at least help keep a message board or guestbook clean.

Recommended Answers

All 7 Replies

Yeah, it's a good idea, but I think that just replacing the entire word with one character is neater so you can see the length of the character (and guess what it is if you really need to know what it was :p).

Thanks, Gary! :) You've got a lot of really good hacks over at vB.org

Thanks :)

Watch out when filtering curse words. If the text submitted handles text formating like <b> tags (or b wrapped in brackets like this and other forums do), I could easily do something <b>s</b>hit and it would spell out you know what with the "s" in bold. I think this is a bug in vBulletin. I know I tried it on a few forums and it worked.

very nice

couldnt you just do striptags() and/or mysqlescapestring()
this should filter off tags, or you could custom code a bb code like parser so that it replaces <b>, etc. with nothing.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.