敏感词过滤的php代码,ThinkPHP敏感词汇过滤
如果內容中包含敏感詞匯,則返回False,否則返回True。
很簡單的代碼。
請將文件放置于 "項目/ORG/SensitiveFilter.class.php"下。
其中 “ SensitiveThesaurus.php”是一個敏感詞匯數組,大家可以任意添加內容。
1.[代碼][PHP]代碼<?php
/**
* 敏感詞匯過濾
* User: konakona
* Date: 12-11-28
* Time: 下午4:37
* 調用方式
* if(false === SensitiveFilter::filter($content)){
* error("含有敏感詞匯");
* }
*/
class SensitiveFilter extends Think{
public static $wordArr = array();
public static $content = "";
/**
* 處理內容
* @param $content
*
* @return bool
*/
public static function filter($content){
if($content=="") return false;
self::$content = $content;
empty(self::$wordArr)?self::getWord():"";
foreach ( self::$wordArr as $row){
if (false !== strstr(self::$content,$row)) return false;
}
return true;
}
public static function getWord(){
self::$wordArr = include 'SensitiveThesaurus.php';
}
}
2.[文件]
SensitiveThesaurus.php
3.[圖片] 被攔截.jpg
本文原創發布php中文網,轉載請注明出處,感謝您的尊重!
總結
以上是生活随笔為你收集整理的敏感词过滤的php代码,ThinkPHP敏感词汇过滤的全部內容,希望文章能夠幫你解決所遇到的問題。