RE: [PHP] word filter

From: Date: Mon, 01 Oct 2001 08:33:06 +0000
Subject: RE: [PHP] word filter
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-69425@lists.php.net to get a copy of this message
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

« previous php.general (#69425) next »