tags:

views:

33

answers:

3

This tests a textarea input agains bad words...

$bad_words = array('bad', 'words')

foreach( $bad_words as $bad ){
 if( stristr($posted, $bad) !== FALSE )
 {
  $contains_bad_words = TRUE;
 }    
}

Now is there any way to make this match 'bad', 'BAD', 'Bad', 'BaD' etc without having to write it into the array in all different cases (Large letters, small letters)?

Thanks

+3  A: 

I think that should do it. strstr is case-sensitive, and stristr is not.

Matchu
stristr will work for sure. I just tested it.
GWW
A: 
strstr() is case-sensitive. For case-insensitive searches, use stristr().

http://us.php.net/strstr

Chris
A: 

$bad_words = array('bad', 'words'); foreach($bad_words as $bad) if(preg_match("/$bad/i",$posted)) $contains_bad_words = TRUE;

Amorphous