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
http://www.bkjia.com/PHPjc/320092.htmlwww.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) {...