I'm working on making a downloadable shoutbox script and am having some problems with the profanity filter. The list of profanities and filtered words is in a separate file. A profanity is on one line with the filtered word on the next. Here's the code:
function profanityfilter($shout){
//This function filters profanities from the shout.
$FileName="lists/profanities.php";
if($FilePointer=fopen($FileName,"r")){
$list=file($FileName);
fclose($FilePointer);
}
for ($n = 0; $n < count($list); $n=$n+2){
$profanity = $list[$n];
$filtered = $list[$n+1];
$shout=str_replace($profanity,$filtered,$shout);
}
return $shout;
}
The filter just flat out doesn't work. You can try it at http://www.duffworld.org/shoutpro/. The filtered words are f, s, and b***** (without the astericks of course). I've already tested to see if $profanity and $filtered are being assigned properly, and they are. The problem is in the line "$shout=str_replace($profanity,$filtered,$shout);". It's probably a really stupid mistake. Anyone know what's wrong with it?