Category: >> Perl Code >> Bad Word Filter Bookmark and Share

<< lastnext >>

Snippet Name: Bad Word Filter

Description: Check a string and filter out prohibited words. Good for forums, guestbooks, etc.

Also see:
» Censor Message Text
» Filter Empty Array Elements
» Naughty Word Censor
» SQL Injection Filter

Comment: (none)

Author: CoderZone
Language: PERL
Highlight Mode: PERL
Last Modified: March 05th, 2009

#put the badwords in a string separated by a pipe delimiter
$badwords =qq~phentermine|poker|keno|blackjack|gammon|ringtones|viagra"~;
@check_fields = ("comments", "name", "email");
#my test field values
#$IN{'city'} = qq~my drug is valium ~;
#$IN{'realname'} = qq~i have some lorazepam ~;
sub check_badwords {
foreach $check_field (@check_fields) {
  $this_field = eval('$'."in{'".$check_field."'}");
    if ($this_field =~ m/($badwords)/gi) {
  #print qq~found $1 in field '$check_field' \n~;
    print qq~Thanks for adding to our Guestbook! \n~;
There haven't been any comments added for this snippet yet. You may add one if you like.  Add a comment 
© | users online: 8