Laravel Profanity Filter - Powerful PHP package for detecting, filtering, and masking profanity in multiple languages. Supports leet speak, custom word lists, case sensitivity, and seamless Laravel integration.
waad/laravel-profanity-filter is a Laravel package for laravel profanity filter - powerful php package for detecting, filtering, and masking profanity in multiple languages. supports leet speak, custom word lists, case sensitivity, and seamless laravel integration..
It currently has 20 GitHub stars and 9.684 downloads on Packagist (latest version v1.2.1).
Install it with composer require waad/laravel-profanity-filter.
Discover more Laravel packages by waad
or browse all Laravel packages to compare alternatives.
Last updated

A powerful, flexible, and easy-to-use PHP Laravel package for detecting, filtering, and masking profanity in multiple languages. Includes advanced features such as leet speak detection, custom word lists, language auto-detection, and real-time configuration.
.txt or .json files per languagePHP 8.0+Laravel 8+composer require waad/laravel-profanity-filter
Publish the configuration file:
php artisan vendor:publish --tag="profanity-filter"
Publish the words (Optional) ⚠️:
php artisan vendor:publish --tag="profanity-words"
You can configure the package by editing the profanity-filter.php file in the config directory.
hasProfanity methoduse Waad\ProfanityFilter\Facades\ProfanityFilter;
$text = "This is a test string with some profanity like fuck and shit.";
$hasProfanity = ProfanityFilter::hasProfanity($text);
echo $hasProfanity; // true
filter methoduse Waad\ProfanityFilter\Facades\ProfanityFilter;
$text = "This is a test string with some profanity like fuck and shit.";
$filteredText = ProfanityFilter::filter($text);
echo $filteredText; // This is a test string with some profanity like **** and ****.
getProfanityWords methoduse Waad\ProfanityFilter\Facades\ProfanityFilter;
$text = "This is a test string with some profanity like fuck and shit.";
$profanityWords = ProfanityFilter::getProfanityWords($text);
print_r($profanityWords);
// Output: Array ( [0] => fuck [1] => shit )
setLanguage methoduse Waad\ProfanityFilter\Facades\ProfanityFilter;
ProfanityFilter::setLanguage('en'); // default is null (auto detect language)
$text = "This is a test string with some profanity like fuck and shit.";
$filteredText = ProfanityFilter::filter($text);
echo $filteredText; // This is a test string with some profanity like **** and ****.
setCaseSensitive methoduse Waad\ProfanityFilter\Facades\ProfanityFilter;
ProfanityFilter::setCaseSensitive(true); // default is false
$text = "This is a test string with some profanity like fuck and Fuck.";
$filteredText = ProfanityFilter::filter($text);
echo $filteredText; // This is a test string with some profanity like **** and Fuck.
setDetectLeetSpeak methoduse Waad\ProfanityFilter\Facades\ProfanityFilter;
ProfanityFilter::setDetectLeetSpeak(true); // default is true
$text = "This is a test string with some profanity like f@ck and sh!t.";
$filteredText = ProfanityFilter::filter($text);
echo $filteredText; // This is a test string with some profanity like **** and ****.
setConfig methodYou can update the package configuration in real time using Laravel's config() helper, or by editing the profanity-filter.php file in the config directory.
use Waad\ProfanityFilter\Facades\ProfanityFilter;
config(['profanity-filter.custom_words.en' => ['custom']]);
ProfanityFilter::setConfig(config('profanity-filter'));
$text = "This is a test string with some profanity like fuck and shit.";
$filteredText = ProfanityFilter::filter($text);
echo $filteredText; // This is a test string with some profanity like **** and ****.
importWordsFromFile methodYou can import additional profanity words from a file (JSON or TXT) at runtime using the importWordsFromFile method. This is useful for dynamically extending the list of profane words without modifying the config file.
use Waad\ProfanityFilter\Facades\ProfanityFilter;
// Import words from a TXT file
ProfanityFilter::importWordsFromFile(storage_path('app/profanity-words.txt'), 'en');
// Import words from a JSON file
ProfanityFilter::importWordsFromFile(storage_path('app/profanity-words.json'), 'en');
$text = "This is foo and bar and alpha.";
$filteredText = ProfanityFilter::filter($text);
echo $filteredText; // This is *** and *** and *****.
addWords methodYou can add custom profanity words in real time using the addWords method. This is useful for dynamically adding words without modifying the config file.
use Waad\ProfanityFilter\Facades\ProfanityFilter;
// Add a single word
ProfanityFilter::addWords('badword', 'en');
// Add multiple words at once
ProfanityFilter::addWords(['testword1', 'testword2'], 'en');
ProfanityFilter::addWords(collect(['testword3', 'testword4']), 'en');
$text = "This is badword and testword1 and testword3 and testword4.";
$filteredText = ProfanityFilter::filter($text);
echo $filteredText; // This is ******* and ********* and ********* and *********.
removeWords methodYou can remove profanity words from the filter in real time using the removeWords method.
use Waad\ProfanityFilter\Facades\ProfanityFilter;
// Remove a single word
ProfanityFilter::removeWords('damn', 'en');
// Remove multiple words at once
ProfanityFilter::removeWords(['shit', 'hell'], 'en');
$text = "This is damn and shit.";
$hasProfanity = ProfanityFilter::hasProfanity($text);
echo $hasProfanity; // false
clearWords methodYou can clear all profanity words for a specific language in real time using the clearWords method.
use Waad\ProfanityFilter\Facades\ProfanityFilter;
// Clear all words for English
ProfanityFilter::clearWords('en');
$text = "This is damn and shit.";
$hasProfanity = ProfanityFilter::hasProfanity($text);
echo $hasProfanity; // false
getWords methodYou can retrieve all profanity words for a specific language using the getWords method.
use Waad\ProfanityFilter\Facades\ProfanityFilter;
$words = ProfanityFilter::getWords('en');
print_r($words);
// Output: Array ( [0] => damn [1] => shit [2] => ... )
use Waad\ProfanityFilter\Facades\ProfanityFilter;
$text = "This is a test string with some profanity like f@ck and sh!t.";
ProfanityFilter::setLanguage('en')
->setDetectLeetSpeak(true)
->setCaseSensitive(false)
->addWords('customword', 'en');
ProfanityFilter::hasProfanity($text); // true
ProfanityFilter::filter($text); // This is a test string with some profanity like *@** and **!*.
// Chaining word management methods
ProfanityFilter::addWords(['word1', 'word2'], 'en')
->removeWords('word1', 'en')
->clearWords('fr');
$words = ProfanityFilter::getWords('en');
Contributions are welcome! Please feel free to submit a pull request.
To run the tests, you can use the following command:
composer test
This package is open-sourced software licensed under the MIT license.