coxlr / laravel-profanity
一个用于在文本字符串中查找并删除脏话的 Laravel 扩展包。
1.1.0
2024-03-13 23:27 UTC
Requires
- php: ^8.1
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.14
- orchestra/testbench: ^8.0|^9.0
- phpunit/phpunit: ^9.3.0|^10.0
- vimeo/psalm: ^4.18|^5.23
- vlucas/phpdotenv: ^5.3
README
安装
此扩展包需要 PHP 8.1 和 Laravel 10 或更高版本。
使用 Composer 安装 PHP 客户端库
composer require coxlr/laravel-profanity
该扩展包将自动注册 Profanity
提供者和外观。
您可以使用以下命令发布配置文件:
php artisan vendor:publish --provider="Coxlr\Profanity\ProfanityServiceProvider" --tag="config"
然后更新 config/profanity.php
文件以包含您的凭证。或者,您也可以更新您的 .env
文件,如下所示
PROFANITY_REPLACEMENT_CHARACTER=* PROFANITY_REPLACEMENT_LENGTH=4 PROFANITY_REPLACEMENT_LANGUAGES=en,es
使用方法
要使用 Profanity,您可以使用外观,或者从服务容器中请求实例。
清理字符串
$cleansedText = Profanity::clean('Using the facade to cleanse a string.'); /* This function returns a string with any profanity found replaced with replace value set in the config. */
或者
$profanity = app('profanity'); $cleansedText = $profanity->clean('Using the instance to cleanse a string.');
检查字符串是否干净
$isClean = Profanity::isClean('The string to be checked.'); /* This function returns a boolean value. If the string is clean, it will return true. If the string contains profanity, it will return false. */
设置用于搜索脏话时要使用的语言
$cleansedText = Profanity::setLanguages('en,es,fr')->clean('The string to be cleansed.');
设置在搜索和替换脏话时的严格模式
严格模式会将找到的任何脏话都替换掉,即使它位于单词内部,而不仅仅是整个单词。
$cleansedText = Profanity::setStrict(true)->clean('The string to be cleansed.'); $isClean = Profanity::setStrict(true)->isClean('The string to be checked.');
测试
composer test
更新日志
请参阅 更新日志 以获取有关最近更改的更多信息。
贡献
请参阅 贡献指南 以获取详细信息。
安全
如果您发现任何安全相关的问题,请通过电子邮件 hey@leecox.me 反馈,而不是使用问题跟踪器。
鸣谢
许可
MIT 许可证 (MIT)。有关更多信息,请参阅 许可文件。