Detailed explanation of word filtering principle in ucenter

*文
Release: 2023-03-18 20:14:01
Original
1593 people have browsed it

This article mainly introduces the principle of word filtering in ucenter, and analyzes the related SQL field definitions and filtering functions of words in ucenter in the form of examples. It involves PHP regular replacement and related operation skills of strings and arrays. Friends in need You can refer to it. I hope to be helpful.

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

Filter word list:

##1UCenterAdministAccess大/visit/is2UCenterAdminist465545/4655/is##34
id admin find replacement findpattern
UCenterAdminist fdsaf dfsa /fdsaf /is
UCenterAdminist 有chances at /有chances/is
Building 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;
}
Copy after login

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);
}
Copy after login
preg_replace() Each parameter (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().

Related recommendations:

PHP generates text-based Morse code

php text replacement specified times

##php processes repeated lines in text documents

The above is the detailed content of Detailed explanation of word filtering principle in ucenter. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!