Re: naughty words / filter

From: Date: Thu, 21 Aug 2003 13:58:50 +0000
Subject: Re: naughty words / filter
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-160307@lists.php.net to get a copy of this message
> // example #1: in the script the text in the variable $guestbook does not > get replaced. > <? > $dirty_words = array("badword1","badword2","badword3"); > $guestbook = stripslashes($message); > foreach ($dirty_words as $word){ > $message = str_replace($word, "****", $guestbook); > } > echo $message; > ?> > ............................. > this won't help your script work, but will tidy it up, but try using a regular expression... $dirty_words = array("|badword1|i","|badword2|i","|badword3|i"); //the i will make it case insensetive, which is extra useful... $message = preg_replace( $dirty_words, "****", stripslashes($message) ); echo $message;

« previous php.general (#160307) next »