elmas156 Posted January 10, 2011 Share Posted January 10, 2011 Hello everyone, I have a website where users are able to send and receive messages. I am trying to devise a way that I can prevent abusive messages from being sent. The best way that I can think of to do this is to use a few key words that would likely be used in an abusive message (basically, any curse word). Does anyone have any ideas on how I can check the text before it is sent for certain key words? Thanks in advance for any help or ideas. Quote Link to comment https://forums.phpfreaks.com/topic/223973-recognizing-specific-words-in-text/ Share on other sites More sharing options...
Zurev Posted January 10, 2011 Share Posted January 10, 2011 Hello everyone, I have a website where users are able to send and receive messages. I am trying to devise a way that I can prevent abusive messages from being sent. The best way that I can think of to do this is to use a few key words that would likely be used in an abusive message (basically, any curse word). Does anyone have any ideas on how I can check the text before it is sent for certain key words? Thanks in advance for any help or ideas. Well you could have a bbcode type thing with curse words, just using str_replace with arrays if it's a simple project. $bad = array("badword1", "badword2", "badword3"); $good = array(); $text = "Yeah I badword1 badword2 badword3"; $text = str_replace($bad, $good, $text); Simple... Quote Link to comment https://forums.phpfreaks.com/topic/223973-recognizing-specific-words-in-text/#findComment-1157427 Share on other sites More sharing options...
QuickOldCar Posted January 10, 2011 Share Posted January 10, 2011 I made a masking safe filter, can do just words or entire posts if wanted. Can view a demo and the download is at the bottom. http://get.blogdns.com/dynaindex/Safe-Filter/ Quote Link to comment https://forums.phpfreaks.com/topic/223973-recognizing-specific-words-in-text/#findComment-1157429 Share on other sites More sharing options...
elmas156 Posted January 10, 2011 Author Share Posted January 10, 2011 Zurev, this works to replace any "bad words" with something else, but what about totally preventing the message from being sent if there are any of the "bad words" included in the message? Is there a way to recognize whether or not any of the words are included in the text then maybe setting a variable, say "$ok" to have the value "y" if no bad words are included and value "n" is there are bad words included? This would prevent a message like "I'm going to beat the _ out of you!" or "You're a _ idiot!" These messages would still be abusive and I want to completely prevent them from being sent. Of course, I understand that some messages would still be sent if certain terminology was not used, such as, "You're an idiot!" but I'll try to deal with that if/when it comes. Quote Link to comment https://forums.phpfreaks.com/topic/223973-recognizing-specific-words-in-text/#findComment-1157432 Share on other sites More sharing options...
Zurev Posted January 10, 2011 Share Posted January 10, 2011 Zurev, this works to replace any "bad words" with something else, but what about totally preventing the message from being sent if there are any of the "bad words" included in the message? Is there a way to recognize whether or not any of the words are included in the text then maybe setting a variable, say "$ok" to have the value "y" if no bad words are included and value "n" is there are bad words included? This would prevent a message like "I'm going to beat the _ out of you!" or "You're a _ idiot!" These messages would still be abusive and I want to completely prevent them from being sent. Of course, I understand that some messages would still be sent if certain terminology was not used, such as, "You're an idiot!" but I'll try to deal with that if/when it comes. Something like that would halt it from sending if it contained bad words, but that just checks if the word exists in the text, not as a word. $badWords = array("badword1", "badword2", "badword3"); $anyBadWords = array(); $text = "yeah's he's a badword1, I told him badword2 betta watch out before I badword3 him up!"; foreach ($badWords as $badWord) { if (stripos($text, $badWord)!=FALSE) { $anyBadWords[] = $badWord; } } // Before you send it... if (!empty($anyBadWords)) { exit("Sorry, there were ".count($anyBadWords)." bad words found within your entry."); } I would go into using regular expressions so somebody doesn't get restricted for no reason, i.e. Password contains ass - so it would be blocked. Quote Link to comment https://forums.phpfreaks.com/topic/223973-recognizing-specific-words-in-text/#findComment-1157530 Share on other sites More sharing options...
elmas156 Posted January 10, 2011 Author Share Posted January 10, 2011 Thanks very much for your help! I think I can tweak this into some code that I can use for my purpose. Have a great day! Quote Link to comment https://forums.phpfreaks.com/topic/223973-recognizing-specific-words-in-text/#findComment-1157550 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.