Jump to content

recognizing specific words in text


elmas156

Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.