I'm trying to set up a bad word filter on my chat script, but when it outputs it does not replace all the bad words. It seems to only like the last bad word on the list. Can anyone help, I've been struggling with this problem for the last two days? The bad words are stored in a file with each word on its own line. Here is the current code.
<html>
<?php
require "config.php";
//require "db.php";
require "header.php";
?>
<p align="center"><font size="5"><a href="chat.php">Post a comment</a></font></p>
<?php
//Nag message
$file = "install.php";
if(file_exists($file))
{
print ("<p align = 'center'><font size='7'>Warning! install.php still exists! This is a major security
hole. Please delete install.php to get rid of this message.</font></p>");
}
?>
<hr color="#000080">
<?php
/*
if ($con['pruneing'] == 1)
{
$td = time();
$timeout = $td - $con['pruneing_sec'];
//echo $timeout;
$del = mysql_query("DELETE FROM $chat WHERE stamp < $timeout AND `group` = '$group'");
}
*/
$chatline = array();
$filterall = array();
$message_array = file($directory);
for($i=0; $i < sizeof($message_array); $i++)
{
list($chatline['date'], $chatline['ip'], $chatline['name'], $chatline['message'], $chatline['mail'], $chatline['url'], $chatline['avatar'], $chatline['color'], $chatline['group']) = explode("|", $message_array[$i]);
@$output .= ("<img border='0' src='".$chatline['avatar']."' style='float: left'><font color='".$chatline ['color']."'>".$chatline['message']."</font><br>");
$output .= $chatline ['name'];
if (!empty($chatline['url'] ))
{
$output .= (" <a href =' ".$chatline ['url']."'><img border = '0' src = 'images/globe.gif' width = '20' height = '20' alt = 'Go to site' title = 'Go to site'></a>");
}
if (!empty($chatline['mail']))
{
$output .= (" <a href = 'mailto:".$chatline ['mail']."'><img border = '0' src = 'images/email05.gif' width = '20' height = '20' title = 'Send an email' alt = 'Send an email'></a>");
}
// Admin buttons
//
$output .= ("
<img border = '0' src = 'images/padlock.gif' width = '20' height = '20' title = 'Ban user' alt = 'Ban user'>
<img border = '0' src = 'images/delete.jpg' width = '20' height = '20' title = 'Delete comment entry' alt = 'Delete comment entry'>
");
//Back out of admin
//
$chatline ['date'] = strtotime("$gmt hours",$chatline ['date']);
$output .= ("<br>".gmdate('l, F d, Y - g:i:s A', $chatline ['date'])."<br>IP: ".$chatline ['ip']."<br><br>");
}
//Bad word MySQL connect
$convert = $output;
$j=0;
$filterall = file("messages/words.txt");
if ($nobadwords == 1)
{
while($j < sizeof($filterall))
{
$convert = eregi_replace ($filterall[$j], "<b>CUS WORD</b>",$convert);
$j++;
}
}
reset($filterall);
echo $convert;
?>
<hr color="#000080">
<p align="center"><font color="#000080" size="1"> © Gabriel Brightwell</font></p>
</body>
</html>