I am trying to use bad words filter but I want to load the bad words from a txt file on my server but some how failed to do so.here is my bad words filter code
function badWordFilter(&$text, $replace)
{
$patterns = array(
'/butt/i',
'/poop/i',
'/crap/i'
);
$replaces = array(
'b***',
'p***',
'c***'
);
$count = 0;
if($replace){
$text = preg_replace($patterns, $replaces, $text, -1, $count);
} else {
foreach($patterns as $pattern){
$count = preg_match($pattern, $text);
if($count > 0){
break;
}
}
}
return $count;
}
$any=BadWordFilter($qtitle,0);
$any=BadWordFilter($qtitle,1);
now to load the badwords from txt file I am using the following in place of
$patterns = array(
'/butt/i',
'/poop/i',
'/crap/i'
);
Following
$file_array = file('/path/to/badword.txt');
$patterns = array();
foreach ($file_array as $word_combo)
{
$patterns[] = explode(',', $word_combo);
}
but it gave me delimiter error
Warning: preg_match() expects parameter 1 to be string, array given in myfile.php on line 60
Warning: preg_match() expects parameter 1 to be string, array given in myfile.php on line 60
Warning: preg_match() expects parameter 1 to be string, array given in myfile.php on line 60
Warning: preg_replace() [function.preg-replace]: Delimiter must not be alphanumeric or backslash in myfile.php on line 57
Warning: preg_match() expects parameter 1 to be string, array given in myfile.php on line 60
Warning: preg_match() expects parameter 1 to be string, array given in myfile.php on line 60
Warning: preg_match() expects parameter 1 to be string, array given in myfile.php on line 60
Warning: preg_replace() [function.preg-replace]: Delimiter must not be alphanumeric or backslash in myfile.php on line 57
line 60--$count = preg_match($pattern, $text);
line 57--$text = preg_replace($patterns, $replaces, $text, -1, $count);