Jump to content
xisto Community
fsoftball

Offensive Language Filter

Recommended Posts

Hi,I would like to create a demo page to show perspective users how my site will work. This would entail allowing a stranger to fill in several forms. I am concerned that these users will fill in the form with offense content. Is there an offensive language filter for PHP? For MySQL? Is there something that Xisto.com could provied (if so, what lever hosting do you need....free?)Thanks.

Share this post


Link to post
Share on other sites

I dont know if this works perfectly, but i did something similar with my chat.

First, when your setting the variable for the users message input:
$usermessage //for example
you filter it with the badwords function, giving:
$usermessage=badwords($usermessage);

then somewhere else (for comfort in the same page) make a bad words filter array

Function badwords($post){$badwords=array(    '*BLEEP*'=>"$$$$",    '*BLEEP*'=>"%$%#",    '*BLEEP*'=>"^&^%",    '*BLEEP*'=>"@#$#",    '*BLEEP*'=>"@$#@", //you can easily expand your array       );   $post=str_replace(array_keys($badwords), array_values($badwords), $post);    return $post; }

Like i said, this is a small amount of code ive taken from my chat but it works great, you can edit it to fit your needs.

Share this post


Link to post
Share on other sites

I was going to suggest something along the line of using a string replace in PHP to replace offensive words with asterisks and the like, but the problem with this is that you absolutely cannot filter all swear words because users can still use 1337 to bypass all the words that you've blocked.I suggest using the script that Hmmz has provided and monitor whatever the user sends to you for a couple of times. Then, you can change the script to include more words as necessary.

Share this post


Link to post
Share on other sites

I don't know what you were planning for the demo, but unless you need the prospective users to share content you don't really need a filter, do you? As long as whatever is filled in is only seen by the visitor (and possibly you) then they can type whatever they want.But otherwise staring off with a reasonable array, and then monitoring input is probably the best option.

Share this post


Link to post
Share on other sites

Create a function named censor with the parameter string. Below you will find the function and an example.

 

function censor($string) {$banned_words = array();$banned_words[] = 'BANNED WORD';$banned_words[] = 'BANNED WORD';$banned_words[] = 'BANNED WORD';foreach ($banned_words AS $banned_word) {str_replace('$banned_word','-censored-',$string);}}

--Example--

 

$message = 'What the *BANNED WORD* is your problem?!';$message = censor($message);

--New Message--

 

'What the -censored- is your problem?!'

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.