Regular expression can also be another way out of this. I did something to detect sites with inappropriate urls not long ago, that way:
#blacklist.php
return array(
'(.*)\.(xxx)',
'4tube\.com',
'clickme\.net',
'cnnamador\.com',
'extremefuse\.com',
'fakku\.net',
'fux\.com(?!\.br)', //Com .br é de advogados
'heavy-r\.com',
'kaotic\.com',
'xhamster\.com',
'porndoe\.com',
'pornocarioca\.com',
'rapebait\.net',
'redtube\.com',
'sex\.com',
'vidmax\.com',
'wipfilms\.net',
'xvideos\.(com|net)',
'porntube\.com',
);
That’s why I use a function:
public static function isBlockedHost($url)
{
$keywords = (array) include 'blacklist.php';
foreach ($keywords as $regex) {
if (preg_match("/{$regex}/i", $url) > 0) return true;
}
return false;
}
Think that if I could do this with hosts, you can also do this with words you want to block. As they appear, you can add them to an array.
More interesting maybe you should think about creating a comment moderator, because sometimes even if the bad word itself does not appear in the sentence, it can still be offensive due to its context.
– abfurlan