943,331 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 22064
  • PHP RSS
Nov 16th, 2003
0

Simple Banned Words Filter

Expand Post »
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.
Similar Threads
Reputation Points: 11
Solved Threads: 0
Junior Poster in Training
himerus is offline Offline
82 posts
since Aug 2003
Nov 23rd, 2003
0

Re: Simple Banned Words Filter

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).
Team Colleague
Reputation Points: 53
Solved Threads: 5
PHP/vBulletin Guru
Gary King is offline Offline
360 posts
since Nov 2003
Nov 23rd, 2003
0

Re: Simple Banned Words Filter

Or people could also use my hack for vBulletin, which replaces censored text with an image instead - it helps visually

http://www.vbulletin.org/forum/showt...threadid=53665
Team Colleague
Reputation Points: 53
Solved Threads: 5
PHP/vBulletin Guru
Gary King is offline Offline
360 posts
since Nov 2003
Nov 23rd, 2003
0

Re: Simple Banned Words Filter

Thanks, Gary! You've got a lot of really good hacks over at vB.org
Administrator
Staff Writer
Reputation Points: 1422
Solved Threads: 162
The Queen of DaniWeb
cscgal is offline Offline
13,645 posts
since Feb 2002
Nov 23rd, 2003
0

Re: Simple Banned Words Filter

Thanks
Team Colleague
Reputation Points: 53
Solved Threads: 5
PHP/vBulletin Guru
Gary King is offline Offline
360 posts
since Nov 2003
Jan 3rd, 2004
0

Re: Simple Banned Words Filter

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.
Team Colleague
Reputation Points: 262
Solved Threads: 18
a.k.a inscissor
samaru is offline Offline
1,227 posts
since Feb 2002
Jan 17th, 2004
0

Re: Simple Banned Words Filter

very nice
Reputation Points: 30
Solved Threads: 2
Light Poster
SMterminator is offline Offline
41 posts
since Jan 2004
Feb 12th, 2006
0

Re: Simple Banned Words Filter

Quote originally posted by SMterminator ...
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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
extermin8tor is offline Offline
14 posts
since Jan 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: page layout help!!!!
Next Thread in PHP Forum Timeline: Next page creator





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC