Nobody likes spam and websites with ton of spams can be annoying to the end users and frustrating to the webmaster or developer. Using regular expression and php function preg_match, we can check for spam as shown in function isSpam below.
/*
* @text: the string of text you want to check for spam
* isSpam function returns true if the text contains spam word(s), return false otherwise.
*/
function isSpam($text)
{
$pattern = "/\b(boobs|adult|adults|penis|adult toys|cialis|viagra|sexy|sex|porn|gay|dick|tits|tit)\b/i";
if(preg_match($pattern, $text, $match))
return true;
else
return false;
}$pattern contains a list of spam words separated by pipe sign |
You can add more spam words to $pattern as you need.
isSpam function is a simple function to help you checking for spam programmatically.