Here is my source
$Message = $_GET["message"];
$Username = htmlspecialchars($_GET["username"]);
$unix = ($_GET["time"]);
include 'mcheck.php';
$file1 = file_get_contents('filter.txt');
$bad_words = explode(PHP_EOL, $file1);
$compare = explode('', $Message);
foreach ($bad_words as $bad_word)
$Message = preg_replace('/\b('.$bad_word.')\b/i', "***", $Message);
echo $Message;
Say the bad word is go
and $Message = I Like to go to school
I want it to echo I Like to *** to school
but instead im getting
***I***Like***To******to***school***
i dont know what the problem is
Your file most likely ends with a newline (which is a good thing: all text-files on *nix systems are supposed to), which means that the last element of
explode(PHP_EOL, $file1)is empty (it’s everything between the last newline and the end of the file, which is nothing). I would recommend writing:using the
trimfunction to eliminate that last newline.