search
Homephp教程PHP开发Analysis of word filtering principles in ucenter

This article analyzes the word filtering principle in ucenter. Share it with everyone for your reference, the details are as follows:

Filter word list

Analysis of word filtering principles in ucenter

Build cache data:

//private
function _get_badwords() {
  $data = $this->db->fetch_all("SELECT * FROM ".UC_DBTABLEPRE."badwords");
  $return = array();
  if(is_array($data)) {
    foreach($data as $k => $v) {
      $return['findpattern'][$k] = $v['findpattern'];
      $return['replace'][$k] = $v['replacement'];
    }
  }
  return $return;
}

Calling method:

$_CACHE['badwords'] = $this->base->cache('badwords');
if($_CACHE['badwords']['findpattern']) {
  $subject = @preg_replace($_CACHE['badwords']['findpattern'], $_CACHE['badwords']['replace'], $subject);
  $message = @preg_replace($_CACHE['badwords']['findpattern'], $_CACHE['badwords']['replace'], $message);
}

Each parameter of preg_replace() (except limit) can be an array. If both pattern and replacement are arrays, their keys will be processed in the order in which they appear in the array. This is not necessarily the same as the numerical order of the index. If an index is used to identify which pattern is to be replaced by which replacement, the array should be sorted with ksort() before calling preg_replace().

I hope this article will be helpful to everyone in PHP programming.

For more articles related to the analysis of word filtering principles in ucenter, please pay attention to the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function