详细代码如下:
复制代码 代码如下:
<?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(过滤注册的用户名)
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(过滤在线编辑器内容)
function filtit($str) {
$this -> blackstr = array(
´/\&/´,
´/\´/´,
´/\"/´,
´/\</´,
´/\>/´,
´/\\\\/´,
´/\//´,
´/-/´,
´/\*/´,
´/ /´
);
$this -> whitestr = array(
´&amp;´,
´&#39;´,
´&quot;´,
´&lt;´,
´&gt;´,
´&#92;´,
´&#47;´,
´&#45;´,
´&#42;´,
´&nbsp;´
);
return preg_replace($this->blackstr, $this -> whitestr, $str);
}
}
class SQLFilter extends Filter { //for filte sql query string(过滤如查询或其它sql语句)
function filtit($str) {
$this -> blackstr = array(
´/\´/´,
´/-/´
);
return preg_replace($this->blackstr, ´´, $str);
}
}
class FileNameFilter extends Filter { //for filte a file name(过滤文件名如下载文件名)
function filtit($str) {
$this -> blackstr = array(
´/[^A-za-z0-9_\.]|\\\\|\^|\[|\]/´
);
return preg_replace($this->blackstr, ´´, $str);
}
}
?>

使用方法如:
复制代码 代码如下:
$filter = new FileNameFilter(); //定义实例
$downFile = $filter->filtit($_GET[´fn´]); //调用过滤方法
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!