gacbaluyot/profanity-filter

A lightweight, multilingual profanity detection and censorship library written in native PHP

Maintainers

Package info

github.com/gacbaluyot/profanity-filter

pkg:composer/gacbaluyot/profanity-filter

Statistics

Installs: 2

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

dev-main / 1.0.x-dev 2025-07-28 17:42 UTC

This package is auto-updated.

Last update: 2026-03-28 18:59:26 UTC


README

A lightweight, multilingual profanity detection and censorship library written in native PHP.

Supports dynamic language loading, custom word lists, and Unicode-safe pattern matching.

๐Ÿš€ Features

  • Detects profanity in text using prebuilt JSON wordlists
  • Supports multiple languages:
    • English (en)
    • Russian (ru)
    • Italian (it)
    • Indonesian (id)
    • Chinese (zh)
    • Japanese (ja)
  • Add or override custom bad words
  • Merge multiple language filters or use all at once
  • Extract, censor, or save profane words
  • PHPUnit test suite included

๐Ÿ“ฆ Installation

Clone the repo and include via Composer:

composer install

Make sure your autoloader can resolve ProfanityFilter\ProfanityFilter from /src.

๐Ÿ“‚ Usage

Basic Detection

use ProfanityFilter\ProfanityFilter;

$filter = new ProfanityFilter('en');

$text = "You idiot!";

if ($filter->containsProfanity($text)) {
    echo "Profanity detected!";
}

Censor Words

$censored = $filter->censor("You dumb bastard!");
echo $censored; // You **** *******!

Get Detected Words

$words = $filter->getProfaneWords("That was stupid and shitty.");
print_r($words); // ['stupid', 'shitty']

Use Multiple Languages

$filter->setLanguages(['en', 'ru']);

Use All Languages

$filter->useAllLanguages();

Add Custom Words

$filter->addCustomWords(['meanie', 'dummy']);

Save & Load Custom Word List

$filter->saveUpdatedWordList(__DIR__ . '/my-words.json');
$filter->setWordListFromFile(__DIR__ . '/my-words.json');

๐Ÿงช Running Tests

vendor/bin/phpunit tests/

Make sure youโ€™ve run:

composer dump-autoload

to register autoload-dev.

๐Ÿ“ Language Wordlist Files

Each language is stored in a separate JSON file in src/data/, e.g.:

src/data/en.json
src/data/ru.json
src/data/zh.json

You can extend these manually or via the library methods.

๐Ÿ“ License

MIT Licensed. Use at your own discretion โ€” offensive content warning applies.

๐Ÿ™Œ Contributions Welcome!

Feel free to fork, submit PRs, or suggest new languages and improvements!