kamu / aman
替换不良词
v1.2.1
2024-09-24 08:32 UTC
Requires
- php: ^8.1
- ext-mbstring: *
Requires (Dev)
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^10.5
README
简单的基于正则表达式的不良词过滤器
这是一个简单的项目,使用PHP中的正则表达式过滤不良词。它提供了用于检查、过滤和从文本中移除不受欢迎的词的功能,这些词考虑到了相似字符。
功能
- 不良词检查:检查字符串是否包含任何不受欢迎的词。
- 不良词过滤器:从文本中移除不受欢迎的词。
- 不良词掩码:将不受欢迎的词替换为掩码字符,例如
*
。
安装
要安装此软件包,您可以使用Composer。
-
在您的项目目录中运行以下命令
composer require kamu/aman
-
在db/lists.php文件中添加您想要过滤的词列表。
return [ 'badword1', 'badword2', // Add more words you want to filter ];
用法
您可以使用Aman类在您的应用程序中过滤不良词。
示例用法
-
检查不良词
use Kamu\Aman; $text = "This is an example with bad words."; $filter = Aman::factory(); if ($filter->check($text)) { echo "This text contains profanity."; } else { echo "This text is clean."; }
-
掩码不良词
$text = "This is an example with bad words."; $maskedText = $filter->masking($text, '*'); echo $maskedText; // Output: "This is an example with *** ****."
-
移除不良词
$text = "This is an example with bad words."; $cleanText = $filter->filter($text); echo $cleanText; // Output: "This is an example with ."
-
从文本中获取不良词
$text = "This is an example with bad words."; $badWords = $filter->words($text); print_r($badWords); // Output: ['bad', 'words']
贡献
我非常欢迎那些想要为Aman做出贡献的人!
安全漏洞
如果您在此Aman中发现任何安全漏洞,请通过dewanakretarta29@gmail.com给DKL发送电子邮件。
许可证
Aman是开源软件,许可证为MIT许可证。