I need to know how to be able to ban a certain word
from within a flat text file inputted on a website.
here is what i got that works, but only with a one word input
ie, if i add "red" to the "email" ban file, then if ya enter "red",
you can not post.
but,
how can i make this routine sort and search a longer string of text?
such as, the user enters:
"the red cat ate the big dog and blood went everywhere, it was really gross"
now, how to i make my routine below read all words, find the word "blood"
and not allow the post? (as if i had banned the word "blood".
here is what i have now that works with single word entries:
open(EMAIL, "email");
$line=<EMAIL>;
close(EMAIL);
@email=split(/\~/, $line);
#$email=$ENV{"REMOTE_ADDR"};
$email=$trevor->param("email");
$url=$trevor->param("url");
$name=$trevor->param("name");
$story=$trevor->param("story");
###### the sub routine that checks story input against the email flat file
foreach $line(@email)
{
if ($story eq $line)
{
print $trevor->header();
print "<html><body bgcolor=000000 text=ffffff link=ff9900 vlink=ff9900 alink=ff9900><center><h1>You do not have the right to post pictures here</h1><br></center></body></html>";
exit();
}
}
now, the above works, but only with one word entries,
"story" is the inputted text from the web page, they can type like 250 words or so
"email" is the name of my flat file that i put banned urls, emails, etc into, and
each entry is seperated with " ~ " (a tilde)
i know nothing about perl, but, i have hacked and beat until i got the above to work,
ie, if i can find snippets, etc, but on my own i am lost
MANY thanks in advance!
Tim
...
@email=split(/\~/, $line);
@forbidden = ('bad','stinking','lousy','words');
foreach $word (@forbidden) { # Loops through forbidden words
if ("@email"=~/\b$word\b/) { # If the word appears in the email...
# or maybe /\b${word}s?\b/ # also does common plurals
print "No way<br />";
exit();
}
}
(Of course, there lots of ways around something like this. If you get real serious with regex, you can really lock the smart alecks out.)