Re: bad word filter
| From: | Don Read | Date: | Tue, 24 Jul 2001 19:58:20 +0000 |
| Subject: | Re: bad word filter | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-59419@lists.php.net to get a copy of this message | ||
On 24-Jul-2001 Ryan Fischer wrote:
>
> Anyway, here's what I would do:
>
> function filterWords($str){
> $badwords = array("shit", "fuck", "ass", "bitch");
> for($i=0; $i<count($badwords); $i++){
> $str = $eregi_replace("$badwords[$i]", "*****", $str);
> }
> return $str;
> }
Un-tested:
$badpat=join('|', $badwords);
$str = $preg_replace("/\b[$badpat]\b/gi", '!*@', $str);
Regards,
--
Don Read dread@texas.net
-- It's always darkest before the dawn. So if you are going to
steal the neighbor's newspaper, that's the time to do it.