Naughty Word Catcher
| From: | Chris Aitken | Date: | Wed, 31 Jan 2001 05:03:32 +0000 |
| Subject: | Naughty Word Catcher | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-37417@lists.php.net to get a copy of this message | ||
Hi all,
Ive just been asked whether I can do the following task.....
When a block of text is submitted via a web form, for it to be checked for offensive words, and rejected if there is.
So I put my brain hard to work and came up with a possibly solution. I know this method should work but im wondering if I should tackle it a different way.
This is just a rough, typed-off-the-top-of-my-head to show the method rather than correct code.
The idea was to have a list of offensive words or phrases in a MySQL database, and the script would take the block of text, and do the following
$query="select naughty_words from prude_list";
$result=mysql_query($query);
while ($loop=mysql_fetch_array($result)) {
$naughty_word_checker = stristr("$block_of_text","$loop[naughty_words]");
if ($naughty_word_checker) {
header("Location: error.php?reason=prudes_wont_like_it");
} else {
header("Location: insert_stuff.php?comment=$block_of_text");
}
}
or is there a better, more efficient way of doing it. Im pretty sure the concept of above will work because if there is a match, stristr() should return text, otherwise it shouldnt return anything (or if im wrong, a little fine tuning will sort that out).
Thanks
Chris