Jump to content

Swear filter


Lyleyboy

Recommended Posts

Hi all,

I'm looking for some advice / ideas.

I have to create a swear filter. I have a mysql table with a load of bad words in it.

What I need to do is filter the content from a form and replace any bad words found.

 

I have no ideas of where to begin. Help!

Link to comment
Share on other sites

Here's one I wrote.  save this into something like filter.php

 

class formFilter {
public function language_filter($string)
{
	$obscenities = array("<<words you don't want>>", "<<another word you don't want>>");
	foreach($obscenities as $curse_word)
	{
		if (stristr(trim($string), $curse_word))
		{
			$length = strlen($curse_word);
			for($i=1; $i<=$length; $i++)
			{
				$stars .= "*";
			}

			/*
			This is where it adds the ip to the banned list automatically

			$ip = $_SERVER['REMOTE_ADDR'];

			$sql = "INSERT INTO banned (ip) VALUES ('$ip')";
			$this->query($sql);
			*/

			$string = eregi_replace($curse_word, $stars, trim($string));
			$stars = "";
		}
	}

	return $string;
}
}

 

then include filter.php.

 

then add

$langFilter = new formFilter();

 

pass form data to it like:

$formData = $langFilter->languageFilter(<<varibale with data>>);

 

the string returned will have *** over the words you put in the array.

 

Let me know if that helps.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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.