导航:首页 > 净水问答 > php实现敏感词过滤

php实现敏感词过滤

发布时间:2022-06-03 02:22:10

『壹』 php怎么过滤

使用单独一个模块,这个模块负责所有的安全处理。

这个模块被包含在所有公开的 PHP 脚本的最前专端(或者非常靠前的属部分)。

参考下面的脚本security.inc

<?php
switch($_POST['form'])
{
case'login':
$allowed=array();
$allowed[]='form';
$allowed[]='username';
$allowed[]='password';
$sent=array_keys($_POST);
if($allowed==$sent)
{
include'/inc/logic/process.inc';
}
break;
}
?>

『贰』 如何在PHP中成功的过滤危险HTML的代码

//php批量过滤post,get敏感数据
if(get_magic_quotes_gpc()){
$_GET=stripslashes_array($_GET);
$_POST=stripslashes_array($_POST);
}

functionstripslashes_array(&$array){
while(list($key,$var)=each($array)){
if($key!='argc'&&$key!='argv'&&(strtoupper($key)!=$key||''.intval($key)=="$key")){
if(is_string($var)){
$array[$key]=stripslashes($var);
}
if(is_array($var)){
$array[$key]=stripslashes_array($var);
}
}
}
return$array;
}
//--------------------------

//替换HTML尾标签,为过滤服务
//--------------------------
functionlib_replace_end_tag($str)
{
if(empty($str))returnfalse;
$str=htmlspecialchars($str);
$str=str_replace('/',"",$str);
$str=str_replace("\","",$str);
$str=str_replace("&gt","",$str);
$str=str_replace("&lt","",$str);
$str=str_replace("<SCRIPT>","",$str);
$str=str_replace("</SCRIPT>","",$str);
$str=str_replace("<script>","",$str);
$str=str_replace("</script>","",$str);
$str=str_replace("select","select",$str);
$str=str_replace("join","join",$str);
$str=str_replace("union","union",$str);
$str=str_replace("where","where",$str);
$str=str_replace("insert","insert",$str);
$str=str_replace("delete","delete",$str);
$str=str_replace("update","update",$str);
$str=str_replace("like","like",$str);
$str=str_replace("drop","drop",$str);
$str=str_replace("create","create",$str);
$str=str_replace("modify","modify",$str);
$str=str_replace("rename","rename",$str);
$str=str_replace("alter","alter",$str);
$str=str_replace("cas","cast",$str);
$str=str_replace("&","&",$str);
$str=str_replace(">",">",$str);
$str=str_replace("<","<",$str);
$str=str_replace("",chr(32),$str);
$str=str_replace("",chr(9),$str);
$str=str_replace("",chr(9),$str);
$str=str_replace("&",chr(34),$str);
$str=str_replace("'",chr(39),$str);
$str=str_replace("<br/>",chr(13),$str);
$str=str_replace("''","'",$str);
$str=str_replace("css","'",$str);
$str=str_replace("CSS","'",$str);

return$str;

}

『叁』 PHP 如何过滤特殊字符 如 ◆ )- : 、 、!! / 等

^

PHP 中的 preg_replace() 函数可以实现

实例:只匹配中文


<?php
$str="php)!!编程";
echopreg_replace("/[^x{4e00}-x{9fa5}]/iu",'',$str);
?>

『肆』 求php实现多个字符过滤功能

if(preg_match('/(词1|词2|词3)+/', $string)){
return false;

}

『伍』 我做了一个留言板现在想用PHP过滤代码,应该怎么做呀详细思路,谢谢!

主要就是替换留言内容中的一些html敏感标签 像"<",">" 等
还有就是校验内容里面是否有一些sql的关键字 想update 等

其实你可以用编辑框Editor 网上有很多

『陆』 php 小问题大侠们.

echo "<a href='#' onclick=\”window.open('dongtai/login.php','用户注册','width=310 height=300')\"";
你要做什么?

『柒』 php 过滤重复词组 相同关键词测过滤掉

楼上瞎扯淡,人家是要实现过滤重复词组,不是要你对他的代码做解释
function replaceRepeated($words)
{
$arrSrc =explode(" ",$words);
$arrDst =array();
foreach($arrSrc as $key=>$val)
{
if(!in_array($val,$arrDst))$arrDst[] =$val;
}
return join(" ",$arrDst);
}
$str ="大家好 今天天气真好啊 在干么啊 今天天气真好啊 没干什么啊";
echo replaceRepeated($str);//输出大家好 今天天气真好啊 在干么啊 没干什么啊
算法很简单:
将原来的语句用空格分隔到数组,然后定义另外一个数组存放过滤后的词组,在循环式检查当前字符串在第二个数组中是否存在,不存在则存放到第二个数组,最后函数返回第二个数组即可

『捌』 php怎样过滤掉特殊字符啊 ☺

过滤掉特殊字符,可以考虑使用字符串替换的方法,在php中替换字符效率最高也是最简单字符替换函数str_replace函数。

使用方法:str_replace(find,replace,string,count)

参数说明:

find 必需。规定要查找的值。

replace 必需。规定替换 find 中的值的值。

string 必需。规定被搜索的字符串。

count 可选。一个变量,对替换数进行计数。

实例:

str_replace("iwind","kiki","iloveiwind,iwindsaid");

将输出 "i love kiki, kiki said"

当然你也可以采取正则替换的方法,该函数是preg_replace

『玖』 php 如何过滤特殊字符,如 ◆ )- : 、 、!! /   等

可以用 str_replace() 函数统一替换,如:
$string = "测试◆例子♂ 在此 !";
$replace = array('◆','♂',')','=','+','$','¥','-','、','、',':',';','!','!','/');
$string = str_replace($replace, '', $string);
echo $string;

阅读全文

与php实现敏感词过滤相关的资料

热点内容
苯铵废水处理 浏览:115
树胶树脂有什么 浏览:760
大金有冷凝水提升泵吗 浏览:775
doit过滤 浏览:17
润滑油滤芯生意怎么样 浏览:894
家用反渗透纯水机怎么接管子 浏览:602
天龙国产14档变速箱滤芯怎么换 浏览:955
edi膜块回收 浏览:591
废水治理的前景概括 浏览:972
昌吉反渗透水处理 浏览:913
公司的污水处理费怎么做账 浏览:467
2018年内蒙古反渗透膜招标信息 浏览:288
山崎蒸馏所标 浏览:237
化工水处理药水 浏览:451
ro反渗透膜75加仑 浏览:277
如何打扫房间的污水 浏览:338
桑塔纳3000空调滤芯在什么位置 浏览:1
美国人怎么处理养殖污水 浏览:591
霍尼韦尔滤芯怎么换 浏览:116
路由器设置了mac过滤可以破解吗 浏览:450