How to realize blacklist filtering by php
Editor to share with you how php to achieve blacklist filtering, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Blacklist filtering
Function is_spam ($text, $file, $split =':', $regex = false) {$handle = fopen ($file, 'rb'); $contents = fread ($handle, filesize ($file)); fclose ($handle); $lines = explode ("n", $contents); $arr = array (); foreach ($lines as $line) {list ($word, $count) = explode ($split, $line); if ($regex) $arr [$word] = $count; else $arr [Preg _ count; else] = $quote } preg_match_all ("~" .implode ('|, array_keys ($arr)). "~", $text, $matches); $temp = array (); foreach ($matches [0] as $match) {if (! in_array ($match, $temp)) {$temp [$match] = $temp [$match] + 1; if ($temp [$match] > = $arr [$word]) return true;} return false;} $file = 'spam.txt'; $str =' This string has cat, dog word' If (is_spam ($str, $file)) echo 'this is spam'; else echo' this is not spam'; ab:3 dog:3 cat:2 monkey:2 is all the content of the article "how to achieve blacklist filtering in php". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!