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.