<?php class Logic_BlackWord { const APP_FORUM = 1; const APP_BLOG = 2; const APP_VOTE = 3; public function getHitList($txt) { $hitList = array(); $max = $this->getMax(); if($max) { $size = 1000; $last = ceil($max/$size); for($page=1;$page<=$last;$page++) { $result = $this->getHitListByPage($txt,$page,$size); if($result) $hitList = array_merge($hitList,$result); } } $hitList2 = array(); foreach($hitList as $hit=>$type) { $hitList2[$type][] = $hit; } return $hitList2; }
The sensitive word replacement algorithm of this class library is 4 times more efficient than str_replace (6,000 sensitive words attached). This class library was written when I had not studied Trie trees. After that, I came into contact with the AC algorithm. The algorithm has a similar structure and logic to AC. They both use trees to exchange space for time, which is very helpful for searching/replacing massive data.
strtr is the representative of the KMP algorithm. It has no advantage in dealing with massive vocabulary, and the vocabulary library must be loaded into the memory every time.
Using the AC algorithm to write extensions and loading the vocabulary into memory is the best way to handle it.
So badword.src.php can be used to learn AC algorithm, learn search and replace, etc.
All resources on this site are contributed by netizens or reprinted by major download sites. Please check the integrity of the software yourself! All resources on this site are for learning reference only. Please do not use them for commercial purposes. Otherwise, you will be responsible for all consequences! If there is any infringement, please contact us to delete it. Contact information: admin@php.cn
Related Article
10 Nov 2016
We have introduced a PHP program that filters some special characters before. Let's upgrade this sensitive word filtering function to be more powerful. With it, we are no longer afraid of adding spaces or other punctuation marks in the middle of sensitive words. ...
09 Aug 2023
PHP form filtering: sensitive word filtering and replacement In the process of developing web applications, we often need to filter and clean the data submitted by users to protect the security of the website and the privacy of the users. Among them, filtering and replacing sensitive words is a very important task. This article will introduce how to use PHP to filter and replace sensitive words, and provide corresponding code examples. The principle of sensitive word filtering and replacement. Sensitive word filtering and replacement refers to detecting sensitive words contained in the data submitted by users and replacing them with specified words.
13 Jul 2016
PHP form sensitive character filtering class, PHP form filtering. PHP form sensitive character filtering class, PHP form filtering This article describes the PHP form sensitive character filtering class and its usage with examples. Share it with everyone for your reference. The specific analysis is as follows: Copy code
19 Aug 2023
PHP learning steps: How to use sensitive words to filter Introduction: In the Internet age, freedom of speech also brings the risk of information dissemination. In order to maintain the health of the network environment and provide a user-friendly experience, sensitive word filtering has become an indispensable part. This article will introduce the learning steps of using sensitive word filtering in PHP and provide corresponding code examples. Step 1: Establish a sensitive lexicon. To use the sensitive word filtering function, you first need to create a sensitive lexicon. The sensitive word library is a list containing all sensitive words to be filtered. OK
Hot Tools
PHP library for dependency injection containers
PHP library for dependency injection containers
A collection of 50 excellent classic PHP algorithms
Classic PHP algorithm, learn excellent ideas and expand your thinking
Small PHP library for optimizing images
Small PHP library for optimizing images