Analysis _php skills of word filtration principle in ucenter

Source: Internet
Author: User
Tags getting started with php php database

This paper analyzes the principle of word filtration in ucenter. Share to everyone for your reference, specific as follows:

Filter words table:

Id Admin Find Replacement FindPattern
1 Ucenteradminist Access Big /Visit/is
2 Ucenteradminist 4655 45 /4655/is
3 Ucenteradminist Fdsaf Dfsa /fdsaf/is
4 Ucenteradminist Have a chance In /have the opportunity to/is

To 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;
}

Call 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 (except the limit) of the preg_replace () can be an array. If both pattern and replacement are arrays, they are processed in the order in which their key names appear in the array. This is not necessarily the same as the numeric order of the index. If you use an index to identify which pattern will be replaced by which replacement, you should sort the array by Ksort () before calling Preg_replace ().

More interested in PHP related content readers can view the site topics: "PHP Security Filtering Skills Summary", "PHP operation and operator Usage Summary", "PHP Network Programming Skills Summary", "PHP basic Grammar Introductory Course", "PHP object-oriented Programming Program", "PHP Array ( Array), "Summary of PHP string usage", "Getting Started with Php+mysql database operations" and "Summary of common PHP database Operations Tips"

I hope this article will help you with the PHP program design.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.