Home > Backend Development > PHP Tutorial > PHP character filtering class, used to filter data entered by various users_PHP tutorial

PHP character filtering class, used to filter data entered by various users_PHP tutorial

WBOY
Release: 2016-07-21 15:46:45
Original
1090 people have browsed it

The detailed code is as follows:

Copy code The code is as follows:

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 english symbol
);
return preg_replace($this->blackstr, ´´, $str );
}
}
class EditorFilter extends Filter { //for article editor filter (filter 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 (filtering such as queries or other sql statements)
function filtit($str ) {
$this -> blackstr = array(
´/´/´,
´/-/´
);
return preg_replace($this->blackstr, ´ ´, $str);
}
}
class FileNameFilter extends Filter { //for filte a file name (filter file name such as downloaded file name)
function filtit($str) {
$this -> blackstr = array(
´/[^A-za-z0-9_.]|\\|^|[|]/´
);
return preg_replace($this ->blackstr, ´´, $str);
}
}
?>

Used as:
Copy code The code is as follows:

$filter = new FileNameFilter(); //Define instance
$downFile = $filter-> filtit($_GET[´fn´]); //Call filtering method

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/320092.htmlTechArticleThe detailed code is as follows: Copy the code as follows: ?php abstract class Filter { //filter parent class private $blackstr = array(); private $whitestr = array(); function filtit($str) {...
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