https://github.com/coxlr/laravel-profanity
A Laravel package to find and remove profanity from text strings.
https://github.com/coxlr/laravel-profanity
Last synced: 5 months ago
JSON representation
A Laravel package to find and remove profanity from text strings.
- Host: GitHub
- URL: https://github.com/coxlr/laravel-profanity
- Owner: coxlr
- License: mit
- Created: 2023-03-09T23:29:17.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2025-02-27T01:30:36.000Z (over 1 year ago)
- Last Synced: 2025-08-29T06:28:36.953Z (9 months ago)
- Language: PHP
- Size: 54.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE.md
- Security: .github/SECURITY.md
Awesome Lists containing this project
README
# A Laravel package to find and remove profanity from text strings.
[](https://packagist.org/packages/coxlr/laravel-profanity)
[](https://github.com/coxlr/laravel-profanity/actions/workflows/run-tests.yml)
[](https://packagist.org/packages/coxlr/laravel-profanity)
## Installation
This package requires PHP 8.1 and Laravel 10 or higher.
To install the PHP client library using Composer:
```bash
composer require coxlr/laravel-profanity
```
The package will automatically register the `Profanity` provider and facade.
You can publish the config file with:
```bash
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:
```dotenv
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
```php
$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
```php
$profanity = app('profanity');
$cleansedText = $profanity->clean('Using the instance to cleanse a string.');
```
### Check if a string is clean or not
```php
$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
```php
$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.
```php
$cleansedText = Profanity::setStrict(true)->clean('The string to be cleansed.');
$isClean = Profanity::setStrict(true)->isClean('The string to be checked.');
```
## Testing
``` bash
composer test
```
## Changelog
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
## Contributing
Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.
## Security
If you discover any security related issues, please email hello@leecox.dev instead of using the issue tracker.
## Credits
- [Lee Cox](https://github.com/coxlr)
## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.