Re: Profanity Filter

From: Date: Fri, 19 Jan 2001 20:22:11 +0000
Subject: Re: Profanity Filter
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-35718@lists.php.net to get a copy of this message
> On Fri, 19 Jan 2001, Sterling Hughes wrote: > > > Its a whip up of what I was talking about, I didn't mean it as real code > > :)... Switch $words to $word and then swith the argument order to in_array > > and yes, it makes sense... > > > > <?php > > $profanities = array("fuck", "shit"); > > > > $words = preg_split("/\s+/", $data); > > foreach ($words as $word) { > > if (in_array($word, $profanities)) { > > echo "you did a naughty thing"; > > break; > > } > > } > > ?> > > > > > > Would be the somewhat sane version... > > > > _Sterling > > > > It still suffers from failing on "goodf***" and "eats***anddie" because of > the lack of spaces. That's why I had to use strpos(). > true it does take em away, that's why I suggest preg_match as the optimal choice... I happen to strongly dislike the strpos() function when used for more than: strpos($str, ":"); ie, one character searches... -Sterling

« previous php.general (#35718) next »