devtrope / profanity-filter
There is no license information available for the latest version (v0.0.4) of this package.
A profanity filter for PHP
v0.0.4
2025-08-07 15:04 UTC
Requires
- php: >=8.1
Requires (Dev)
- phpstan/phpstan: ^2.1
- squizlabs/php_codesniffer: ^3.13
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.