jimmyt1988 Posted October 2, 2009 Share Posted October 2, 2009 Hi all, Just finished off my contact form.. I want to ban swear words.. Is there an easy php mailer thingy that does this? Quote Link to comment https://forums.phpfreaks.com/topic/176297-solved-removing-swearwords-from-contact-form/ Share on other sites More sharing options...
Adam Posted October 2, 2009 Share Posted October 2, 2009 Depends what banning involves.. Starring out the wrong 'uns, or just flatly refusing to send the email? Quote Link to comment https://forums.phpfreaks.com/topic/176297-solved-removing-swearwords-from-contact-form/#findComment-929142 Share on other sites More sharing options...
jimmyt1988 Posted October 2, 2009 Author Share Posted October 2, 2009 flatly refusing. Quote Link to comment https://forums.phpfreaks.com/topic/176297-solved-removing-swearwords-from-contact-form/#findComment-929143 Share on other sites More sharing options...
mikesta707 Posted October 2, 2009 Share Posted October 2, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/176297-solved-removing-swearwords-from-contact-form/#findComment-929157 Share on other sites More sharing options...
jimmyt1988 Posted October 2, 2009 Author Share Posted October 2, 2009 AWESOME.. it works haha, thankyou very much! ahhh bliss.. My contact form is complete.. yehaaaa thankss buddeh Quote Link to comment https://forums.phpfreaks.com/topic/176297-solved-removing-swearwords-from-contact-form/#findComment-929166 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.