Jump to content

Recommended Posts

Ok, I made a quick function, its not perfect, but it may help you out.

function buildBadVariants($arr){
$lets = array('i', 'l', 'e', 'a', 's', 't', 'o');
$replace = array('1', '1', '3', '4', '5', '7', '0');
foreach($arr as $word){
	foreach($lets as $key =>$let){
		if (substr_count($word, $let) > 0){
			$new = str_replace($let, $replace[$key], $word);
			$arr[] = $new;
		}
	}
	$arr[] = str_replace($lets, $replace, $word);
}
return array_unique($arr);
}

function isBad($str, $bad){
$tokens = explode(" ", $str);
foreach ($tokens as $word){
	if (in_array($word, $bad)){
		return "$str: you dirty boy<br />";
	}
}
return "$str: comment is clean<br />";
}


$bad = array("fuck", "shit", "bastard", "fucker", "fucking", "bitch", "dick");


$comment = "fuck you!";
$comment2 = "oh sh1t";
$comment3 = "sh1771ng d1ck n1pples";
$comment4 = "I am just a wholesome farm boy";

echo isBad($comment, buildBadVariants($bad));
echo isBad($comment2, buildBadVariants($bad));
echo isBad($comment3, buildBadVariants($bad));
echo isBad($comment4, buildBadVariants($bad));

output:

fuck you!: you dirty boy
oh sh1t: you dirty boy
sh1771ng d1ck n1pples: you dirty boy
I am just a wholesome farm boy: comment is clean

 

just to explain a few things, the getbadVariants function will take your array of normal swear words, and add elements replacing certain letters in those swear words with corresponding "1337 speak" numbers. It tries to get most variations (it doesn't get them all) but it tries to prevent hiding bad words by testing for the numbered ones too. just as an example, if i do this line (iusing the same variable $bad as before)

print_r(buildBadVariants($bad));

 

the output is

Array 
( [0] => fuck 
[1] => shit 
[2] => bastard 
[3] => fucker 
[4] => fucking 
[5] => bitch 
[6] => dick 
[8] => sh1t 
[9] => 5hit 
[10] => shi7 
[11] => 5h17 
[12] => b4st4rd 
[13] => ba5tard 
[14] => bas7ard 
[15] => b4574rd 
[16] => fuck3r 
[18] => fuck1ng 
[20] => b1tch 
[21] => bi7ch 
[22] => b17ch 
[23] => d1ck ) 

 

obviously you can change this to fit your needs. hope this helps

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.