I have adapted this function to filter profanity from a guestbook. Somehow the text file does not fill the array. Each entry in the file ends with a newline. If I define the array in the function, the function works fine, replacing the offensive words with *s. Can someone tell me what I might have done wrong with either the file or the function?
function language_filter($comments)
{
$obscenities = file("foul_language.txt");
foreach ($obscenities as $curse_word)
{if (stristr(trim($comments),$curse_word))
{$length=strlen($curse_word);
for ($i = 1; $i <= $length; $i++)
{
$stars .= "*";
}
$comments = eregi_replace($curse_word, $stars, trim($comments));
$stars = "";
}
}
return $comments;
}
function language_filter($comments)
{
$obscenities = file("foul_language.txt");
foreach ($obscenities as $curse_word)
{if (stristr(trim($comments),$curse_word))
{$length=strlen($curse_word);
for ($i = 1; $i <= $length; $i++)
{
$stars .= "*";
}
$comments = eregi_replace($curse_word, $stars, trim($comments));
$stars = "";
}
}
return $comments;
}
Comment