Simple Banned Words Filter
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.
[php]
$bad_words = explode('|', 'badword1|badword2|badword3|etc|etc');
foreach ($bad_words as $naughty)
{
$comments = eregi_replace($naughty, "#!@%*#", $comments);
}
[/php]
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.
himerus
Junior Poster in Training
84 posts since Aug 2003
Reputation Points: 11
Solved Threads: 0
Thanks, Gary! :) You've got a lot of really good hacks over at vB.org
cscgal
The Queen of DaniWeb
19,421 posts since Feb 2002
Reputation Points: 1,474
Solved Threads: 229
Watch out when filtering curse words. If the text submitted handles text formating like tags (or b wrapped in brackets like this and other forums do), I could easily do something shit 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.
samaru
a.k.a inscissor
1,256 posts since Feb 2002
Reputation Points: 262
Solved Threads: 18