php spam check function isSpam

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.

This entry was posted in PHP and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>