RE: [PHP] word filter
| From: | Maxim Maletsky \(PHPBeginner.com\) | Date: | Mon, 01 Oct 2001 08:35:24 +0000 |
| Subject: | RE: [PHP] word filter | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-69426@lists.php.net to get a copy of this message | ||
Sorry, I meant since PHP 4 only, as it is when function in_array() was
introduced
Maxim Maletsky
www.PHPBeginner.com
-----Original Message-----
From: Maxim Maletsky (PHPBeginner.com)
[mailto:php-general@phpbeginner.com]
Sent: lunedì 1 ottobre 2001 10.33
To: '_lallous'; php-general@lists.php.net
Cc: 'Kristjan Kanarik'; 'Richard Heyes'
Subject: RE: [PHP] word filter
There's a better way to do this:
<?
$naughty_words = array(
'poop',
'bum',
'religion'
);
echo in_array($text, $naughty_words) ? "found bad words!" : "text is
clean!"; ?>
Since PHP though...
P.S: are you considering 'region' a naughty word, _lallous? Careful
there...
Maxim Maletsky
www.PHPBeginner.com
-----Original Message-----
From: _lallous [mailto:elias_bachaalany@yahoo.com]
Sent: lunedì 1 ottobre 2001 11.15
To: php-general@lists.php.net
Subject: Re: [PHP] word filter
$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
>
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net To
contact the list administrators, e-mail: php-list-admin@lists.php.net
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net To
contact the list administrators, e-mail: php-list-admin@lists.php.net