Package Data | |
---|---|
Maintainer Username: | gcphost |
Package Create Date: | 2016-11-23 |
Package Last Update: | 2020-07-03 |
Home Page: | |
Language: | PHP |
License: | AGPL-3.0 |
Last Refreshed: | 2024-11-14 15:18:36 |
Package Statistics | |
---|---|
Total Downloads: | 308,457 |
Monthly Downloads: | 2,955 |
Daily Downloads: | 109 |
Total Stars: | 50 |
Total Watchers: | 2 |
Total Forks: | 16 |
Total Open Issues: | 4 |
Filter profanity, or other bad words, out of a string using Laravels localization feature or with any PHP application and some custom coding.
composer require askedio/laravel5-profanity-filter
Register the service providers in Laravel 5.4 or lower to enable the package:
Askedio\Laravel5ProfanityFilter\Providers\ProfanityFilterServiceProvider::class,
php artisan vendor:publish
You can edit the default list of words to filter along with the settings in config/profanity.php
.
replaceWith
can also be a string of chars to be randomly chosen to replace with, like '&%^@#'
.
You can create your own list of words, per language, in resources/lang/[language]/profanity.php
.
$string = app('profanityFilter')->filter('something with a bad word');
The $string
will contain the filtered result.
You can also define things inline
$string = app('profanityFilter')->replaceWith('#')->replaceFullWords(false)->filter('something with a bad word'));
You can also use the profanity
filter with Laravels Validation feature:
$request->validate([
'title' => 'required|profanity|unique:posts|max:255',
]);
filter($string = string, $details = boolean)
pass a string to be filtered.
[
"orig" => "",
"clean" => "",
"hasMatch" => boolean,
"matched" => []
]
reset()
reset replaceWith
and replaceFullWords
to defaults.
replaceWith(string)
change the chars used to replace filtered strings.
replaceFullWords(boolean)
enable to replace full words, disable to replace partial.
You can also use this package without Laravel.
use Askedio\Laravel5ProfanityFilter\ProfanityFilter;
$config = []; // Data from `resources/config/profanity.php`
$badWordsArray = []; // Data from `resources/lang/[lang]/profanity.php`
$profanityFilter = new ProfanityFilter($config, $badWordsArray);
$string = $profanityFilter->filter('something with a bad word');
This package is based on banbuilder.