This function will check in a string for words which are not allowed, defined in an array. Function is case-insensitive. So you are allowed to use only upper or lowercase letters.
function show_invalid_words($text, $array)
{
for ($i = 0; $i < count($array); $i++)
{
if (preg_match("/$array[$i]/i", $text))
return false;
}
return true;
}
Exmaple
$bad_words = array('this', 'andX');
echo (int)show_invalid_words('HELLO! This is jusT a phrase. Simple And well', $bad_words);
The above will out 0 as one of the words are found.
Mail this!
- Comments (0)
- PingBacks (0)
- TrackBacks (0)


» Latest comments