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){
    $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;







--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to