详细代码如下:
复制代码代码如下:
abstractclassFilter{//filterparentclass
private$blackstr=array();
private$whitestr=array();
functionfiltit($str){
//dosomething
}
}
classLoginFilterextendsFilter{//foruserloginfilteusername(过滤注册的用户名)
functionfiltit($str){
$this->blackstr=array(
´/[x7f-xff]/´,//filterchineseincludechinesesymbol
´/W/´//filterallenglishsymbol
);
returnpreg_replace($this->blackstr,´´,$str);
}
}
classEditorFilterextendsFilter{//forarticleeditorfilter(过滤在线编辑器内容)
functionfiltit($str){
$this->blackstr=array(
´/&/´,
´/´/´,
´/"/´,
´/´,
´/>/´,
´/\\/´,
´///´,
´/-/´,
´/*/´,
´//´
);
$this->whitestr=array(
´&´,
´'´,
´"´,
´<´,
´>´,
´\´,
´/´,
´-´,
´*´,
´ ´
);
returnpreg_replace($this->blackstr,$this->whitestr,$str);
}
}
classSQLFilterextendsFilter{//forfiltesqlquerystring(过滤如查询或其它sql语句)
functionfiltit($str){
$this->blackstr=array(
´/´/´,
´/-/´
);
returnpreg_replace($this->blackstr,´´,$str);
}
}
classFileNameFilterextendsFilter{//forfilteafilename(过滤文件名如下载文件名)
functionfiltit($str){
$this->blackstr=array(
´/[^A-za-z0-9_.]|\\|^|[|]/´
);
returnpreg_replace($this->blackstr,´´,$str);
}
}
?>
使用方法如:
复制代码代码如下:
$filter=newFileNameFilter();//定义实例
$downFile=$filter->filtit($_GET[´fn´]);//调用过滤方法
您可能感兴趣的文章:php过滤HTML标签、属性等正则表达式汇总php正则过滤html标签、空格、换行符的代码(附说明)PHP过滤★等特殊符号的正则PHP中过滤常用标签的正则表达式PHP正则表达式过滤html标签属性(DEMO)php中过滤非法字符的具体实现PHP中字符安全过滤函数使用小结php表单敏感字符过滤类php过滤所有恶意字符(批量过滤post,get敏感数据)PHP使用正则表达式实现过滤非法字符串功能示例