mofodojodino/profanity-filter

从字符串中过滤掉粗俗语。

1.3.0 2016-05-11 00:19 UTC

This package is auto-updated.

Last update: 2024-09-11 02:31:28 UTC


README

一个简单的类,用于测试字符串中是否存在粗俗语。

检查操作

直接匹配

直接检查字符串中的粗俗语是否与不良词表中的词匹配。例如 badword

替换

使用每个字母的替代字符检查字符串中的粗俗语。例如 bâdΨ0rd

隐藏

检查带有标点符号的字符串中的粗俗语。例如 b|a|d|w|o|r|d

重复

检查字符重复的字符串中的粗俗语。例如 bbaaddwwoorrdd

组合

也适用于上述组合。例如 b|â|d|Ψ|0|rr|d

安装

通过composer安装此包。

php composer.phar require developer/profanity-filter

用法

/* default constructor */
$check = new Check();
$hasProfanity = $check->hasProfanity($badWords);
$cleanWords = $check->obfuscateIfProfane($badWords);

/* customized word list from file */
$check = new Check('path.to/wordlist.php');

/* customized word list from array */
$badWords = array('bad', 'words'); // or load from db
$check = new Check($badWords);

致敬

必须提到以下项目,因为它为我提供了正则表达式和粗俗语列表的良好基础。

https://github.com/fastwebmedia/Profanity-Filter

感谢 @jackcsk 的贡献,添加了使用普通数组而不是文件作为粗俗语列表的功能。从版本 > v1.3.0 可用。

许可

ProfanityFilter 是开源软件,许可协议为 MIT 协议