bvtvd / words-filter
dirty words filter
Installs: 3 039
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=5.4.0
Requires (Dev)
- phpunit/phpunit: ^6.5
This package is auto-updated.
Last update: 2024-12-04 22:26: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()