Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize blacklist filtering by php

Shulou Source: shulou.com Published: 2022-06-01 03:24:44 10月04日 Update

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!

Tags: Blacklist blackname article content not much most more knowledge industry information channel channel reference learning help Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Shulou Technology Shulou Information MySQL macOS