PHP character filter class, used to filter the data _php skills of various user input

Source: Internet
Author: User
The detailed code is as follows:
Copy Code code as follows:

<?php
Abstract class Filter {//filter parent class
Private $blackstr = Array ();
Private $whitestr = Array ();
function Filtit ($STR) {
Do something
}
}
Class Loginfilter extends Filter {//for User login Filte username (filter registered username)
function Filtit ($STR) {
$this-> blackstr = Array (
´/[\x7f-\xff]/´,//filter Chinese include Chinese symbol
´/\w/´//filter all 中文版 symbol
);
Return Preg_replace ($this->blackstr,´´, $STR);
}
}
Class Editorfilter extends Filter {//for Article editor filter (Filtering online editor content)
function Filtit ($STR) {
$this-> blackstr = Array (
´/\&/´,
´/\´/´,
´/\"/´,
´/\</´,
´/\>/´,
´/\\\\/´,
´/\//´,
´/-/´,
´/\*/´,
´/ /´
);
$this-> whitestr = Array (
´&´,
´'´,
´"´,
´<´,
´>´,
´\´,
´/´,
´-´,
´*´,
´ ´
);
Return Preg_replace ($this->blackstr, $this-> whitestr, $STR);
}
}
Class Sqlfilter extends Filter {//for filte SQL query string (filter such as query or other SQL statement)
function Filtit ($STR) {
$this-> blackstr = Array (
´/\´/´,
´/-/´
);
Return Preg_replace ($this->blackstr,´´, $STR);
}
}
Class FilenameFilter extends Filter {//for filte a file name (filter file name follows file name)
function Filtit ($STR) {
$this-> blackstr = Array (
´/[^a-za-z0-9_\.]| \\\\|\^|\[|\]/´
);
Return Preg_replace ($this->blackstr,´´, $STR);
}
}
?>

use methods such as:
Copy Code code as follows:

$filter = new FilenameFilter (); Defining instances
$downFile = $filter->filtit ($_get[´fn´]); Call filtering method

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.