devtrope/profanity-filter
最新稳定版本:v0.0.4
Composer 安装命令:
composer require devtrope/profanity-filter
包简介
A profanity filter for PHP
关键字:
README 文档
README
A lightweight and customizable PHP package for detecting and censoring profanity in text.
Includes multiple sensitivity levels, support for custom word lists, and is PSR-12 and PHPStan compatible.
Features
- Detects offensive words in strings
- Supports multiple filtering levels:
low,medium,high - Supports multiple languages (en, fr)
- Custom blacklist support via JSON file
- Add or remove words dynamically at runtime
- Fully typed and ready for static analysis
- Easy integration with existing projects
Installation
Install via Composer:
composer require devtrope/profanity-filter
Usage
Basic usage
use ProfanityFilter\ProfanityFilter; use ProfanityFilter\ProfanityLevel; $filter = new ProfanityFilter(); $text = "You little piece of shit!"; echo $filter->clean($text); // You little piece of ****!
With a specific language
$filter = new ProfanityFilter(ProfanityLevel::HIGH, 'fr');
With a custom blacklist
$filter = new ProfanityFilter( ProfanityLevel::HIGH, 'fr', __DIR__ . '/my-custom-blacklist.json' );
{
"low": ["wordlow"],
"medium": ["wordmedium"],
"high": ["wordhigh"]
}
Add or remove words at runtime
$filter->addWord('uglyword'); $filter->removeWord('otheruglyword');
Check if a text contains profanity
if ($filter->containsProfanity($text)) { echo "Inappropriate content detected!"; }
Language support
Currently supported locales:
en- Englishfr- Français
Profanity levels
Each level includes all words from the previous level:
| Level | Description |
|---|---|
| LOW | Mild profanity |
| MEDIUM | Default, balanced |
| HIGH | Agressive filtering |
License
MIT License - see LICENSE for details.
统计信息
- 总下载量: 5
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2025-08-07