Jump to content

Swear filter


Lyleyboy

Recommended Posts

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
https://forums.phpfreaks.com/topic/169826-swear-filter/#findComment-895943
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.