Jump to content

Checking posts for bad words. Need Help...


ricerocket

Recommended Posts

Hi, I have a script that posts information into my database which work fine and everything. But now after a few spam incidents I'm looking to add a bad word filter type thing. Right now I have a basic setup but I'm not sure what to use to store the words. I'm not that sure how arrays work if that may be what I need but I need somebody's help on this. Below is my example of what I have now:

 

 

/* ----------------- Bad Word Filter --------------------- */
$bwords = "don't know how to make a list of bad words here"
if ( $name === $bwords ) {
$problem = "The name you entered was inappropriate. Please go back and try again.";
}
/* ----------------- Bad Word Filter --------------------- */

 

But like a said I don't know to to check the name against a list of bad words. I'm also thinking about using this for the registration system to get rid of users with bad usernames. So if someone could help that would be great. Thanks

Link to comment
Share on other sites

function filterBadWords($str){

 

// words to filter

$badwords=array( "[naughty word removed]", "[naughty word removed]", "[no swearing please]", "[oops]", "[oops]", "[naughty word removed]", "[oops]", "[oops]" );

 

// replace filtered words with

$replacements=array( "[naughty word removed]", "[how wude!]", "[no swearing please]" );

 

for($i=0;$i < sizeof($badwords);$i++){

  srand((double)microtime()*1000000);

  $rand_key = (rand()%sizeof($replacements));

  $str=eregi_replace($badwords[$i], $replacements[$rand_key], $str);

}

return $str;

}

 

example call : $your_text_on_page = filterBadWords($your_text_from_comments);

got it from http://gr0w.com/articles/code/php_bad_words_filter/

 

try and google next time. it does wonders

Link to comment
Share on other sites

yes I used google and found many scripts including the one you posted but if you took even the SLIGHTEST look at my example you'll see that your posted script is nowhere near able to work in my situation. Not to be rude but reading the entire post before you reply is also good.

 

And for those of you that don't understand...

 

The script that posts the post checks to see if $problem is empty, and if it is empty then it posts so I need a script that can check the name of the poster against the "bad words" and if it matches a word in the list then it sets $problem to an error message which will later be displayed for the user to fix.

Link to comment
Share on other sites

I think the example he provided was more than helpful enoguh to accomplish what you're trying to do.

 

If you want someone to code something ready to snap into your pre-built script, you may want to check out the freelance forum. This forum is meant for assistance, not custom programming.

Link to comment
Share on other sites

is it just me or is everyone being naive tonight?!?!? I'm not looking custom programming!!! I'm asking how I can store a list of words which I can use with this:

 

 /* ----------------- Bad Word Filter --------------------- */
$bwords = "don't know how to make a list of bad words here"
if ( $name === $bwords ) {
$problem = "The name you entered was inappropriate. Please go back and try again.";
}
/* ----------------- Bad Word Filter --------------------- */

 

And ONLY this. How can I make that work?!?!? How can I use The above as in:

 

/* ----------------- Bad Word Filter --------------------- */
$bwords = "don't know how to make a list of bad words here"
if ( $name === $bwords ) {
$problem = "The name you entered was inappropriate. Please go back and try again.";
}
/* ----------------- Bad Word Filter --------------------- */

 

to check for bad words?!?!? I'm not looking for custom friken programing!!!

Link to comment
Share on other sites

Make an array of bad words, then use in_array() to check if their username is in the bad words array.

 

$bwords = array('badword', 'another', 'another', 'etc');
if (in_array($name, $bwords)) {
      $problem = "The name you entered was inappropriate. Please go back and try again.";
}

Link to comment
Share on other sites

Thank you very much Jeremysr. And I just wanted to add, why did you even post discomatt?!?!? If I was looking for someone to make stupid comments I would post in the "degrade me" forum. I'm just a beginner looking for help so unless your offering help then don't post!

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.