Lyleyboy Posted August 11, 2009 Share Posted August 11, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/169826-swear-filter/ Share on other sites More sharing options...
guyfromfl Posted August 11, 2009 Share Posted August 11, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/169826-swear-filter/#findComment-895943 Share on other sites More sharing options...
guyfromfl Posted August 11, 2009 Share Posted August 11, 2009 Im sorry to pass the data to the function use this line of code instead: $formData = $langFilter->language_filter(<<varibale with data>>); Quote Link to comment https://forums.phpfreaks.com/topic/169826-swear-filter/#findComment-895956 Share on other sites More sharing options...
.josh Posted August 11, 2009 Share Posted August 11, 2009 http://www.phpfreaks.com/forums/index.php/topic,228009.0.html Quote Link to comment https://forums.phpfreaks.com/topic/169826-swear-filter/#findComment-895958 Share on other sites More sharing options...
guyfromfl Posted August 11, 2009 Share Posted August 11, 2009 Crayon's is better Quote Link to comment https://forums.phpfreaks.com/topic/169826-swear-filter/#findComment-895960 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.