bvtvd/words-filter

dirty words filter

1.0.2 2018-08-14 07:20 UTC

This package is auto-updated.

Last update: 2024-04-04 21:04:53 UTC


README

敏感词过滤器, 支持中文

安装:

composer require bvtvd/words-filter

使用:

use bvtvd\Filter;  
  
$text = '你的观点很新颖, 但是从历史的维度看, 还存在狭隘的内部缺陷! to be or not to be, that's a question!';
  
$dict = ['观点', '内部缺陷', 'be'];
  
# 基本使用
$filter = new Filter($text, $dict);
echo $filter->clean();
//output: 你的*很新颖, 但是从历史的维度看, 还存在狭隘的*! to * or not to *, that's a question!
  
  
# 自定义替换字符
$blocker = '@';
$filter->blocker($blocker);
echo $filter->clean();
//output: 你的@很新颖, 但是从历史的维度看, 还存在狭隘的@! to @ or not to @, that's a question!
  
# 也可以在初始化的时候直接设置替换字符
$filter = new Filter($text, $dict, $blocker);
  
#  设置文本
$filter->text($text);
# 设置敏感词
$fitler->dict($dict);

  
# 你也可以设置不用的替换模式
$filter->model('preg');     // ['default', 'preg'] 
// preg 模式会替换为对应字符长度的 blocker
  
# 检查是否包含敏感词
$filter->check()