Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Swear word filter 3

Status
Not open for further replies.

serpento

Programmer
Jun 16, 2002
92
GB
I want to put a swear word filter on my weboard.

I will have a list of swear words I want to block in an array called [tt]@swearWords[/tt] and the message being submitted to the weboard in [tt]$message[/tt].

What is the best way to check to see if [tt]$message[/tt] contains any elements of [tt]@swearWords[/tt]?
 
just do a foreach:

foreach $swear (@swearWords) {
$message =~ s/$swear/-beep-/ig;
}

that will substitute each swear with -beep- and in a case-insensitive manor. Steve Kiehl
webmaster@nanovox.com
 
or, in one operation


$swear_word_list 'Apple|IBM|Microsoft|Oracle';

$message =~ s/$swear_word_list/-beep/g; Mike

"Experience is the comb that Nature gives us, after we are bald."

Is that a haiku?
I never could get the hang
of writing those things.
 
Question. How could you not filter the results, but make an error, like "$username contains a swear word. invalid user name." instead of replacing the word with -beep?
 
In answer to Zas:

[tt]if ($username =~ m/$swearWordList/i)
{
die($username." contains a swear word. Invalid user name.");
}
else
{
...allow user name...
}[/tt]

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top