PHP敏感詞過濾


 

--------------------------------------------------------------------------------------------------

$str = "百度http://www.baidu.com,騰訊http://www.qq.com,新浪http://www.sina.com.cn/";;
$arr = array("/百度/", "/騰訊/", "/新浪/");
$prg = '***';
$str = preg_replace($arr, $prg, $str);
echo $str;

--------------------------------------------------------------------------------------------------

$badword = array(
'張三','張三豐','張三豐田'
);
$badword1 = array_combine($badword,array_fill(0,count($badword),'*'));
$bb = '我今張張三張三張三張三張三天開着張三上張三班';
$str = strtr($bb, $badword1);
echo $str;

---------------------------------------------------------------------------------------------------------------------------------------------------------

/*function transgress_keyword($content, $Sensitivewords){ //定義處理違法關鍵字的方法
$keyword = $Sensitivewords; //定義敏感詞
$m = 0;
for($i = 0; $i < count ( $keyword ); $i ++) { //根據數組元素數量執行for循環
//應用substr_count檢測文章的標題和內容中是否包含敏感詞
if (substr_count ( $content, $keyword [$i] ) > 0) {
$m ++;
}
}
return $m; //返回變量值,根據變量值判斷是否存在敏感詞
}

if (transgress_keyword($detail, $Sensitivewords)> 0) { //判斷返回值大於0說明包含敏感詞
echo "<script>alert('您輸入的內容中含有敏感詞');</script>";
} */
//-----------------------------------------------------------------------------------------------------------
/*$num = 0;//定義子串出現次數
//內容
$content=$detail;
//循環檢測
for($i = 0; $i < count($Sensitivewords); $i ++) {
//計算子串在字符串中出現的次數
if (substr_count ($content, $Sensitivewords[$i]) > 0) {
$num ++;
}
}
if($num>0){
echo "有敏感詞存在!";
}*/
//-----------------------------------------------------------------------------------------------------------
/*$blacklist="/".implode("|",$Sensitivewords)."/i";
if(preg_match($blacklist, $detail, $matches)){
print "found:". $matches[0];
} else {
print "not found.";
}*/


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM