Re: word filter
| From: | _lallous | Date: | Mon, 01 Oct 2001 09:14:32 +0000 |
| Subject: | Re: word filter | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-69424@lists.php.net to get a copy of this message | ||
$naughty_words = array(
'poop',
'bum',
'religion'
);
if (eregi(join('|', $naughty_words), $text))
echo "found bad words!";
else
echo "text is clean!";
"Richard Heyes" <richard.heyes@heyes-computing.net> wrote in message
news:NEBBIDEMHHJJCANAAAKFAENCJFAA.richard.heyes@heyes-computing.net...
>
> > Looking for a function which checks the user input for unwanted (mostly
> > rude) words. Those words should be defined first in array or so of
> > course... should be case insensitive as well.
>
> $text = 'This text contains a naughty word: Bum';
> $naughty_words = array(
> 'poop',
> 'bum',
> 'religion'
> );
>
> function naughty_words($text, $naughty_words){
> $text = strtolower($text);
> foreach($naughty_words as $value){
> if(strpos($text, strtolower($value)) !== FALSE)
> return TRUE;
> }
>
> return FALSE;
> }
>
> echo naughty_words($text, $naughty_words) ? 'Found naughty words' : 'Text
is
> clean';
>
> --
> Richard Heyes
> "I know not with what weapons World War III will be fought, but World War
IV
> will be fought with sticks and stones." - Albert Einstein
>
>