coxlr/laravel-profanity

A Laravel package to find and remove profanity from text strings.

1.1.0 2024-03-13 23:27 UTC

This package is auto-updated.

Last update: 2024-11-14 16:33:08 UTC


README

Latest Version on Packagist Tests Total Downloads

Installation

This package requires PHP 8.1 and Laravel 10 or higher.

To install the PHP client library using Composer:

composer require coxlr/laravel-profanity

The package will automatically register the Profanity provider and facade.

You can publish the config file with:

php artisan vendor:publish --provider="Coxlr\Profanity\ProfanityServiceProvider" --tag="config"

Then update config/profanity.php with your credentials. Alternatively, you can update your .env file with the following:

PROFANITY_REPLACEMENT_CHARACTER=*
PROFANITY_REPLACEMENT_LENGTH=4
PROFANITY_REPLACEMENT_LANGUAGES=en,es

Usage

To use Profanity you can use the facade, or request the instance from the service container.

Clean a string

$cleansedText = Profanity::clean('Using the facade to cleanse a string.');

/*
  This function returns a string with any profanity found replaced with replace value set in the config.
*/

Or

$profanity = app('profanity');

$cleansedText = $profanity->clean('Using the instance to cleanse a string.');

Check if a string is clean or not

$isClean = Profanity::isClean('The string to be checked.');

/*
  This function returns a boolean value. If the string is clean, it will return true. If the string contains profanity, it will return false.
*/

To set the languages to use when searching for profanity

$cleansedText = Profanity::setLanguages('en,es,fr')->clean('The string to be cleansed.');

To set strict mode when search for and replace profanity

Strict mode will replace any profanity found even if it is found within a word, and not just the exact word.

$cleansedText = Profanity::setStrict(true)->clean('The string to be cleansed.');

$isClean = Profanity::setStrict(true)->isClean('The string to be checked.');

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email hey@leecox.me instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.