/**
* Created by JetBrains PhpStorm.
* User: lsl
* Date: 13-8-28
* Time: 下午2:58
* 敏感词过滤工具类
* 使用方法
* echo FilterTools::filterContent("你妈的我操一色狼杂种二山食物","*",DIR."config/word.txt",$GLOBALS["p_memcache"]["bad_words"]);
*/
class FilterTools {
public static $keyword = array();
/**
* 从文件中加载敏感词
* @param $filename
* @return array
*/
static function getBadWords($filename){
$file_handle = fopen($filename, "r");
while (!feof($file_handle)) {
$line = trim(fgets($file_handle));
array_push(self::$keyword,$line);
}
fclose($file_handle);
return self::$keyword;
}
/**
* @param $content 待处理字符串
* @param $target 替换后的字符
* @param $filename 敏感词配置文件
* @param $memconfig 缓存配置文件
* @return 处理后的字符串
*/
static function filterContent($content,$target,$filename,$memconfig){
$mem = new BadWordsMemcache($filename,$memconfig);
$keyword = $mem->getList();
if(count($keyword) == 0){
$keyword = self::getBadWords($filename);
}
return strtr($content, array_combine( $keyword, array_fill(0,count($keyword), $target)));
}
}
/**
* 敏感词缓存处理类
* Class BadWordsMemcache
* User: lsl
*/
class BadWordsMemcache{
var $memcache;
var $key;
var $list;
var $filename;
function __construct($filename,$memconfig) {
$this->filename = $filename;
if(!class_exists("P_Memcache")){
require_once DIR."lib/memcache.class.php";
}
$this->key = "bad_words";
$this->memcache = new P_Memcache();
$this->memcache->config = $memconfig;
$this->memcache->connect();
print_r($this->memcache);
$this->init();
}
function __destruct() {
$this->memcache->close();
}
/**
* 初始化
* @param bool $isReset
*/
function init($isReset = false){
$this->list = $this->memcache->get($this->key)?$this->memcache->get($this->key):array();
if(count($this->list)==0 || $isReset){
$this->list = filterTools::getBadWords($this->filename);
$this->memcache->set($this->key, $this->list);
$log_data = Log::formatData($this->list);
Log::logWrite($log_data, 'bad.words','init');
}
}
/**
* 获取列表
* @return mixed
*/
function getList(){
return $this->list;
}
}

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

MinGW - Minimalist GNU for Windows
這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。

SublimeText3 Linux新版
SublimeText3 Linux最新版

DVWA
Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中

Atom編輯器mac版下載
最受歡迎的的開源編輯器

Safe Exam Browser
Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。