Am trying to implement a little bit of code found on stack overflow which covers a spam words filter. When i just type a spam word the function works however when I type in a bunch of text before the spam word it passes. I've checked the source and I must be missing something, can anyone help?
code is:
function strpos_arr($haystack, $needle) {
if(!is_array($needle)) $needle = array($needle);
foreach($needle as $what) {
if(($pos = strpos($haystack, $what))!==false) return $pos;
}
return false;
}
function I'm calling it like is:
if(strpos_arr($text, $bad_words)) {
return false;
} else {
return true;
}
the array is just a simple array with a lot of bad words like so:
$bad_words = array(
'bad word 1',
'bad word 2');
link to original article: Using an array as needles in strpos
Thanks