I'm building a web app with php and the codeigniter framework, and one of the requirements for the client is to implement a 'swear word' filter on from validation. Does anyone know of any prebuilt solutions written in php? Or alternatively, an exhaustive list of curse words that I can format into a php syntaxed array and check for their presence in a user's input? Thanks!
This should be able to get you started with the basic idea, but you'll have to fill the bad words in yourself. You can download a list of bad words here.
However, I must warn you that swear-word filters have some insurmountable issues. The English language is too flexible to prevent people from spelling swear words in a host of different ways. Even if you can block @$$h01e
, you'll never reliably block αṡṡhølε
, which can easily be produced by a character translator. There's no way you can even begin to filter out all the possibilities when each word and letter can have 20+ potential substitutes.
Plus, once people realize you have a swear-word filter, it may become a game to figure out how to thwart it, which can lead to more swearing than you started with! If people want to swear, they will find a way to do so. Fortunately, there are plenty of sites that have already dealt with this problem. What you can do is make them not want to swear by giving them the best experience with your website and content possible, and providing a simple flag feature so users can notify you of the unpreventable cases.
Stackoverflow has no curse word filter, and how often do you see swearing here? Don't send a computer to do a human's job. :D