Hey everyone,
I am writing a simple profanity filter in PHP. Can anyone tell my why, in the following code, the filter works (it will print [explicit]) for the $vowels array and not the $lines array which I constructing from a text file?
function clean($str){
$handle = fopen("badwords.txt", "r");
if ($handle) {
while (!feof($handle)) {
$array[] = fgets($handle, 4096);
}
fclose($handle);
}
$vowels = array("a", "e", "i", "o", "u", "A", "E", "I", "O", "U");
$filter = "[explicit]";
$clean = str_replace($array, $filter, $str);
return $clean;
}
When using $vowels in replace of $array, it works except for lowercase vowels which return:
[[expl[explicit]c[explicit]t]xpl[explicit]c[explicit]t]
instead of
[explicit]
Not sure why that is going on, either.
Any ideas?
Thanks!