<?php // Plug-in 37: Spam Catch // This is an executable example with additional code supplied // To obtain just the plug-ins please click on the Download link $words = array('rolex', 'replica', 'loan', 'mortgaqe', 'viagra', 'cialis', 'acai', 'free', 'stock', 'guaranteed', 'refinancing', 'cartier', 'manhood', 'drugs'); $text = "Hi there. I enjoyed reading your website and will " . "be back for more. Keep up the good work!"; $result = PIPHP_SpamCatch($text, $words); echo "The text <i>'$text'</i> is "; echo $result == 0 ? "spam free." : "suspected spam " . "(score = $result)."; $text = "Brand new replica rolex. Guaranteed quality. " . "http://replicarolex23.com"; $result = PIPHP_SpamCatch($text, $words); echo "<br /><br />The text <i>'$text'</i> is "; echo $result == 0 ? "spam free." : "suspected spam " . "(score = $result)."; function PIPHP_SpamCatch($text, $words) { // Plug-in 37: Spam Catch // // This plug-in takes a string of text and compares it // against a set of known spam keywords. It returns 0 // if no keywords are encountered or an integer indicating // how likely the text is spam: 0-10 = slightly worrying, // 10-20 = possibly spam, 20-30 = likely spam, 30-40 = // probably spam, 40+ almost definitely spam. The // arguments required are: // // $text: The text to spam check // $words: An array of commonly used spam keywords return strlen($text) - strlen(PIPHP_WordSelector($text, $words, '')); } // The function below is there to ensure that the above function // (which relies on it) has access it it. function PIPHP_WordSelector($text, $matches, $replace) { // Plug-in 5: Word Selector // This plug-in takes a string variable containing any // text and then matches and selects words within the // text, highlighting or removing them. // The arguments are: // $text: Text to be modified // $matches: Array of words to match // $replace: String to replace matches with, or if // one of these the text is highlighted: // "u", "b", "i" = underline, bold or italic. foreach($matches as $match) { switch($replace) { case "u": case "b": case "i": $text = preg_replace("/([^\w]+)($match)([^\w]+)/i", "$1<$replace>$2</$replace>$3", $text); break; default: $text = preg_replace("/([^\w]+)$match([^\w]+)/i", "$1$replace$2", $text); break; } } return $text; } ?>
插件说明:
插件接受一个用户输入的字符串,把它与一个关键字表进行比较以确定这个字符串是垃圾信息的可能性,需要以下参数:
$text 需要验证的email地址
$words 用于验证的关键字数组