Quick Search:
 
 Perl Code: Bad Word Filter Jump to:  
Category: >> Perl Code >> Bad Word Filter  

<< lastnext >>

Snippet Name: Bad Word Filter

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

Comment: (none)

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

#!/usr/bin/perl
 
#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 ~;
 
&check_badwords;
 
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~;
 
exit;
 
    }
 }
}


 
   Home |    Search |    Code Library |    Sponsors |    Privacy |    Terms of Use |    Contact Us © 2003 - 2024 psoug.org