Simple Banned Words Filter

Reply

Join Date: Aug 2003
Posts: 82
Reputation: himerus is an unknown quantity at this point 
Solved Threads: 0
himerus's Avatar
himerus himerus is offline Offline
Junior Poster in Training

Simple Banned Words Filter

 
0
  #1
Nov 16th, 2003
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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2003
Posts: 360
Reputation: Gary King will become famous soon enough Gary King will become famous soon enough 
Solved Threads: 5
Team Colleague
Gary King's Avatar
Gary King Gary King is offline Offline
PHP/vBulletin Guru

Re: Simple Banned Words Filter

 
0
  #2
Nov 23rd, 2003
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).
Reply With Quote Quick reply to this message  
Join Date: Nov 2003
Posts: 360
Reputation: Gary King will become famous soon enough Gary King will become famous soon enough 
Solved Threads: 5
Team Colleague
Gary King's Avatar
Gary King Gary King is offline Offline
PHP/vBulletin Guru

Re: Simple Banned Words Filter

 
0
  #3
Nov 23rd, 2003
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2002
Posts: 12,053
Reputation: cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light 
Solved Threads: 131
Administrator
Staff Writer
cscgal's Avatar
cscgal cscgal is offline Offline
The Queen of DaniWeb

Re: Simple Banned Words Filter

 
0
  #4
Nov 23rd, 2003
Thanks, Gary! You've got a lot of really good hacks over at vB.org
Dani the Computer Science Gal
Follow my Twitter feed! twitter.com/DaniWeb
And if you're interested in Internet marketing there is twitter.com/DaniWebAds
Reply With Quote Quick reply to this message  
Join Date: Nov 2003
Posts: 360
Reputation: Gary King will become famous soon enough Gary King will become famous soon enough 
Solved Threads: 5
Team Colleague
Gary King's Avatar
Gary King Gary King is offline Offline
PHP/vBulletin Guru

Re: Simple Banned Words Filter

 
0
  #5
Nov 23rd, 2003
Thanks
Reply With Quote Quick reply to this message  
Join Date: Feb 2002
Posts: 1,135
Reputation: samaru is just really nice samaru is just really nice samaru is just really nice samaru is just really nice 
Solved Threads: 6
Team Colleague
samaru's Avatar
samaru samaru is offline Offline
a.k.a inscissor

Re: Simple Banned Words Filter

 
0
  #6
Jan 3rd, 2004
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.
Check out my blog at http://www.shinylight.com for more stuff about web dev.
Reply With Quote Quick reply to this message  
Join Date: Jan 2004
Posts: 41
Reputation: SMterminator is an unknown quantity at this point 
Solved Threads: 2
SMterminator SMterminator is offline Offline
Light Poster

Re: Simple Banned Words Filter

 
0
  #7
Jan 17th, 2004
very nice
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 14
Reputation: extermin8tor is an unknown quantity at this point 
Solved Threads: 0
extermin8tor extermin8tor is offline Offline
Newbie Poster

Re: Simple Banned Words Filter

 
0
  #8
Feb 12th, 2006
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC