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