Posts

Showing posts from June 13, 2010

bad word filter script in php

This is a simple file based bad word filter PHP function. The function offers a variety of options. You can choose how many letters of the bad word you wish to keep, which character you want to use as the badword "bleeper" as well as a rating for the bad word. The bad words file would be formatted like this: 9   badword 2   anther badword 7   A bad word Phrase 7   YetAnotherWord The first character number is the bad word "rating" the higher the number the worse the word. This can be useful in say, a forum situation where a user can specify their bad word tolerance. So if I pass the function a bad word tolerance of 5, the function will only remove words with a tolerance rating higher than 5. A sample function call would look like this: $myString = "This is a sentence with some badwords, It is an example based on the Yetanotherword file above."; echo filterBadWords($myString,"badwords.txt","*",1,3); If our above badword