Re: Re: naughty words / filter
| From: | Jason Sheets | Date: | Fri, 22 Aug 2003 05:41:58 +0000 |
| Subject: | Re: Re: naughty words / filter | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-160421@lists.php.net to get a copy of this message | ||
Try using str_ireplace, it is str_replace but is case insensitive. str_replace and str_ireplace both can take arrays as parameters for the needle, replacement value. The string functions tend to be much faster than regular expressions, in any case you don't need the foreach..
Jason
Chris Kranz wrote:
// 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){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;$message = str_replace($word, "****", $guestbook);} echo $message; ?> .............................