| | |
Simple Banned Words Filter
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
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.
[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.
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

http://www.vbulletin.org/forum/showt...threadid=53665
Thanks, Gary!
You've got a lot of really good hacks over at vB.org
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

Follow my Twitter feed! twitter.com/DaniWeb
And if you're interested in Internet marketing there is twitter.com/DaniWebAds
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.
![]() |
Similar Threads
- Dirty words filter... (DaniWeb Community Feedback)
Other Threads in the PHP Forum
- Previous Thread: page layout help!!!!
- Next Thread: Next page creator
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl database date directory display download dynamic echo email error fcc file files folder form forms freelancing function functions google href htaccess html image include insert integration ip java javascript joomla limit link login loop mail menu method mlm mod_rewrite multiple mysql oop pageing pagerank parse paypal pdf php printer problem query radio random recursion recursiveloop regex remote script search server sessions sms soap source space sql structure subversion support! syntax system table template tutorial update upload url validation validator variable video web xml youtube






