php mysql敏感词_PHP敏感词处理
composer require lustre/php-dfa-sensitive
use DfaFilter\SensitiveHelper;
/**
* 過濾敏感詞
*/
public function getSensitiveWord() {
$json = new Json();
$red = Red::create();
$wordData = $red->get('tenseven_sensitive_word');
if ($wordData) {
$wordData = json_decode($wordData,true);
} else {
$sensitive_word = M('sensitive_word');
$wordData = $sensitive_word->getField('name',true);
$red->setex('tenseven_sensitive_word',60,json_encode($wordData));
}
$text = $_POST['text'];
$handle = SensitiveHelper::init()->setTree($wordData);
$markedContent = $handle->mark($text, '', '');
$json->S($markedContent);
}
離開事件
$("#text").blur(function(){
var text = $(this).val();
$.ajax({
type:'POST',
url:'__APP__/Public/getSensitiveWord',
data: {text: text},
dataType:'json',
success:function(data){
if(data.errno == 0){
$('#show_sensitive').html(data.data);
}else{
alert(data.errdesc);
return false;
}
}
});
});
可以用表管理敏感詞,sensitive_word。
CREATE TABLE `tf_sensitive_word` (
`id` INT(11) NOT NULL AUTO_INCREMENT COMMENT 'id' ,
`name` VARCHAR(50) NOT NULL COMMENT '名稱' ,
`create_time` INT(11) NOT NULL COMMENT '創(chuàng)建時間' ,
PRIMARY KEY (`id`),
UNIQUE (`name`))
ENGINE = InnoDB CHARSET=utf8 COLLATE utf8_general_ci COMMENT = '抖音敏感詞表';
總結(jié)
以上是生活随笔為你收集整理的php mysql敏感词_PHP敏感词处理的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C#中不常见的运算符功能汇总
- 下一篇: linux cmake编译源码,linu