Jump to content

[SOLVED] php word filter - eregi_replace


daveh33

Recommended Posts

Well, i assume that your message contains a string with no spaces. If all the words had spaces between, it would work. To make it work, remove the spaces in the string that is the 2nd parameter of the explode function:

 

$bad_words = explode(',', 'badword1,badword2,badword3');

 

A more efficient implementation would be:

<?php
<?php
$black_list = array('badword1','badword2','badword3');
str_replace($blacklist,'#!@%*#',$message);
?>

 

Since it avoids the overhead of the regular expression.

<?php
$message  = "badword1 test badword2";
$black_list = array('badword1','badword2','badword3');
$message = str_replace($black_list,'#!@%*#',$message);

echo $message;
?>

$black_list not $blacklist

 

also you need to return the result from str_replace

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.