owowagency/laravel-profanity-validation

使用验证从字符串中过滤脏话。

v0.1.0 2023-02-24 13:31 UTC

This package is auto-updated.

Last update: 2024-09-24 17:02:07 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许可证的许可。