ricerocket Posted March 16, 2008 Share Posted March 16, 2008 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 Quote Link to comment Share on other sites More sharing options...
jkewlo Posted March 16, 2008 Share Posted March 16, 2008 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 Quote Link to comment Share on other sites More sharing options...
ricerocket Posted March 17, 2008 Author Share Posted March 17, 2008 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. Quote Link to comment Share on other sites More sharing options...
discomatt Posted March 17, 2008 Share Posted March 17, 2008 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. Quote Link to comment Share on other sites More sharing options...
ricerocket Posted March 17, 2008 Author Share Posted March 17, 2008 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!!! Quote Link to comment Share on other sites More sharing options...
Jeremysr Posted March 17, 2008 Share Posted March 17, 2008 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."; } Quote Link to comment Share on other sites More sharing options...
ricerocket Posted March 17, 2008 Author Share Posted March 17, 2008 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! Quote Link to comment Share on other sites More sharing options...
jkewlo Posted March 17, 2008 Share Posted March 17, 2008 may i ask why didnt you try that? if u knew $bwords = array('badword', 'another', 'another', 'etc'); would be your array then how come you woudnt add the words into there? Quote Link to comment 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.