checking for spam comments function

with this function, you can scan through your incoming comments and check them for keywords

the function will scan through the comment text and then provide you with a score

as you get more spam comments, you can use them to make the function work better for you by adding the additional keywords that can trigger it

if you wanted to have a ton of keywords you can add them to a db table or just a massive global array

PHP

/* if the spam score is >=4 its probably spam... */
function spam_score($text){
    $spam_score_val = 0;  
    $text = strtolower($text); // lowercase it to speed up the loop
    $spam_words = array("http","peni","pills","sale","cheapest"); 
    foreach($spam_words as $word){
        $count = substr_count($text, $word);
        $spam_score_val += 2 * $count;
    }
    return $spam_score_val;
}

Other Items in php

No Items Found.

Add Comment
Type in a Nick Name here
 
Page Views

This page has been viewed 139 times.

Search Code
Search Code by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code snippits here, mostly for my reference. Also if i find a good site, i usually add it here.

โค๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ•น

Random Quote
Treasure every moment that you have and treasure it more because you shared it with someone special, special enough to spend your time...and remember that time waits for no one.
Unknown