linegg / word-detector
这是一个用于检测敏感词和屏蔽词的PHP包。它具有全面的功能,易于使用。
1.0.1
2021-12-18 09:07 UTC
Requires
- php: >=7.0
README
简介
- 简单易用的敏感词检测包,支持忽略英文字母的大小写。
- PHP >= 7.0
功能
- 搜索匹配的屏蔽词并计算匹配数
- 将屏蔽词替换为自定义符号,例如 '*'
- 自定义无效字符。在遇到这些字符时,匹配将自动跳过
- 匹配时忽略英文字符的大小写
安装
composer require linegg/word-detector
简单示例
<?php // string to be detected $content = 'hello a-bxx,you are a efg!'; // vocabulary array $badWords = ['ab','efg']; $wd = new \Linegg\WordDetector\WordDetector(); // build a trie $wd->buildTree($badWords); // configure negligible characters,such as' - ',' ~ ' $wd->setInvalidWords([' ','-']); // return values includes hit times, hit words, original words and replaced strings List($matchTime, $matchWords, $strWords, $replaceStr) = $wd->search($content, 0, true);