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

This package is auto-updated.

Last update: 2025-08-11 11:47:28 UTC


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.

Latest Stable Version License: MIT Static Analysis: PHPStan Code Style: PSR-12 Downloads PHP Version

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 - English
  • fr - 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.