Skip to content

Instantly share code, notes, and snippets.

@zsmynl
Created January 20, 2014 10:07
Show Gist options
  • Save zsmynl/8517727 to your computer and use it in GitHub Desktop.
Save zsmynl/8517727 to your computer and use it in GitHub Desktop.
一次回复评论的简单过滤总结;php过滤;preg_replace();过滤关键词,过滤邮箱,过滤链接,过滤QQ,手机号;
<?php
$comment=get_var("comment","POST");
if(!empty($comment)){
/* 回复过滤 @zm 2014-1-12 Begin */
$commentFilter['0']='神马';
$commentFilter['1']='浮云';
$commentFilter['2']='QQ';
$commentFilter['3']='qq';
$commentFilter['4']='扣扣';
$commentFilter['5']='秋秋';
$commentFilter['6']='手机';
$comment=str_replace($commentFilter,'我爱中国',$comment);
//过滤邮箱 2014-1-20
$comment=preg_replace("/([a-z0-9]*[-_]?[a-z0-9]+)*@([a-z0-9]*[-_]?[a-z0-9]+)+[\.][a-z]{2,3}([\.][a-z]{2})?/i","",$comment);
//过滤链接 2014-1-20
$comment=preg_replace("/([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}/i","",$comment);
//过滤QQ,手机号 2014-1-20
$comment=preg_replace("/[0-9]{5,}/","",$comment);
/* 回复过滤 2014-1-12 End */
$sql="update wooyun_bugs set corpreply='$comment' where bugid={$bug[bugid]}";
$db->query($sql);
showsuccess("操作成功");
}else{
showerror("操作失败");
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment