I implemented this "bad word" check function in php:
# bad word detector
function check_badwords($string) {
$badwords = array(a number of words some may find inappropriate for SE);
foreach($badwords as $item) {
if(stripos($string, $item) !== false) return true;
}
return false;
}
It works alright, except I'm having a little problem. If the $string is:
Who is the best guitarist ever?
...it returns true, because there is a match with Who ($string) and ho (in $badwords array). How could the function be modified so that it only checks for complete words, and not just part of words?
- check_badwords('She is a ho'); //should return true
- check_badwords('Who is she?'); //should return false
Thanks!