導航:首頁 > 凈水問答 > 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實現敏感詞過濾相關的資料

熱點內容
廢水檢測裝置 瀏覽:436
空氣濾芯製作什麼東西 瀏覽:599
樹脂標號什麼意思 瀏覽:600
甜米酒發酵好要不要蒸餾 瀏覽:622
安利車載空氣凈化器怎麼樣 瀏覽:943
寶寶不吃奶頭用吸奶器吸會回奶么 瀏覽:867
垃圾填埋廠的反滲透裝置 瀏覽:12
凈水器使用前先要放掉多少水 瀏覽:160
水泵房上方有污水管 瀏覽:623
武昌凈水神器怎麼樣 瀏覽:22
生產空氣凈化器企業屬於什麼行業 瀏覽:65
開封污水處理廠項目中標 瀏覽:796
350w小型凈化器多少錢 瀏覽:693
宏森污水處理 瀏覽:68
污水提升器廠家推薦 瀏覽:444
沁園185e凈水機濾芯怎麼安裝 瀏覽:291
污水水解酸化池加什麼葯劑 瀏覽:565
自流平地面和環氧樹脂 瀏覽:801
本田思域拆機油濾芯用什麼扳手 瀏覽:286
找907乙烯基樹脂生產廠家 瀏覽:629