naughty words / filter

From: Date: Thu, 21 Aug 2003 13:33:18 +0000
Subject: naughty words / filter
Groups: php.general 
Request: Send a blank email to php-general+get-160296@lists.php.net to get a copy of this message
Hi, I'm trying to filter a word - in this case - called badword1 - to be replaced with asterisks. Listed below is my .html form and .php receiving script. I've also added the same script which gets a hardcoded string. In the first example, the output still shows the original message _without_ replacing the badword whereas in the second example with the hardcoded string - it is getting replaced with *****. Any assistance would be greatly appreciated. Thank you. Tony Ritter ................................ <html> <form action="themessage.php" method="post"> <p> Your message:<br> <textarea name="message" cols="40" rows="5"> </textarea><br> <input type ="submit" name="submit" value="Submit"> </form> </html> .................... // 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; ?> ............................. // example #2: in this snippet, the hardcoded string $guestbook gets replaced with **** <? $guestbook="Boy, that Tony - he is a real badword1." $dirty_words = array("badword1","badword2","badword3"); $message = $guestbook; foreach ($dirty_words as $word){ $message = str_replace($word, "****", $message); } echo $message; ?>

« previous php.general (#160296) next »