profanity filter

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
croskerry
Forum Newbie
Posts: 1
Joined: Thu Jul 03, 2003 5:38 pm
Location: Hamilton, Ontario

profanity filter

Post by croskerry »

I am writing a standard guestbook application. However, I have to make absolutely sure that no profanity appears on this particular site. I could have the entries sit in the DB and wait to be approved by me but that would mean a lot of work on my part.

Does anyone know of a script that filters out dirty words? If not, how about a list of dirty words that I could filter against?

Thanks,
Dan
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

uh...don't think i am allowed to post 500 sickest word you can think of here :roll:.

what you could is to have a table with all the words you want to replace, e.g.

field 1: ASP
field 2: A*P (asp is a bad word for me :P)

then u can use php to replace words when a enerty is subbmited or soemthing...quite easy, i made it few days ago but don't have now.

OR you can post your email address here and people will send you so many words that you'll pass out lol....

even better!, make a form for people to enter words which thery think are "bad", let them put into the table, this way you will get a VERY big list of words........or something

i have't slept for 32 hours so this prolly won't make much sense.....good luck.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Do what i do, filter before it goes into the database.

Code: Select all

<?php
$badword = "bitch";
$filter = "female dog";
$Array["MessegeBody"] = eregi_replace($badword, $filter, $Array["MessegeBody"]);
?>
Store all your words and replacements in a database and loop this snipplet calling out all the things from the DB in the right place and you have your very own word filter.

Note: This can be used for a smilie/bbcode type thing too.

Code: Select all

<?php
$bbcode = ":wink:";
$replace = "<img src="images/wink.gif">";
$Array["MessegeBody"] = eregi_replace($bbcode, $replace, $Array["MessegeBody"]);
?>
Enjoy. 8)
Post Reply