search
HomePHP LibrariesOther librariesSensitive word filtering php class library
Sensitive word filtering php class library
<?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.

Disclaimer

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

PHP sensitive word filtering advanced versionPHP sensitive word filtering advanced version

10Nov2016

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. ...

PHP sensitive word filteringPHP sensitive word filtering

25Jul2016

PHP sensitive word filtering

PHP sensitive word filtering codePHP sensitive word filtering code

25Jul2016

PHP sensitive word filtering code

PHP form filtering: sensitive word filtering and replacementPHP form filtering: sensitive word filtering and replacement

09Aug2023

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.

PHP form sensitive character filtering class, PHP form filtering_PHP tutorialPHP form sensitive character filtering class, PHP form filtering_PHP tutorial

13Jul2016

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

PHP learning steps: How to use sensitive word filteringPHP learning steps: How to use sensitive word filtering

19Aug2023

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

See all articles