So guyz here is the package that will be very useful to you .if you are planning to create peace or want to filter some bad words from your laravel website or app then this package is made for you ( seriously ) . by default bad words are filterd by *** or but you can set it way you like for ex. –BEEP—
Profanity Filter takes strings as input and removes any bad curse words that the string might have. It check the string for specific blacklist which must match as a sperate word to be considered as a curse word. If a curse word is found, then it will replace the curse word with a censor character the user chooses (default is *).
This package is intended to used with Laravel. Tested and working with laravel 5.1.
This code is based on Fastwebmedia/Profanity-Filter. A major part of it is taken from there and I added the things that I thought it required.
ok so lets get started with installtion ,installation of any package in very easy via composer just require the package
$ composer require sworup/profanityfilter
After installtion add facade and providers array
'Sworup\ProfanityFilter\ProfanityServiceProvider' to your providers array.
If you wish to use the Facade then add
'Profanity' => 'Sworup\ProfanityFilter\Profanity'
The package will automatically use the config file containing the list of banned words.
here is the basic usage of this package
$swear_word = ['dog']; $blacklist = ['puppy']; $replace = ['a' => '(a|a\.|a\-|4|@|Á|á|À|Â|à|Â|â|Ä|ä|Ã|ã|Å|å|α|Δ|Λ|λ)']; $profanity_filter = new sworup\ProfanityFilter($swear_words, $blacklist, $replace); echo $profanity_filter->clean('Dog, puppy badpuppy baddog!', '$');
The above code would return:
array( 'old_string' => 'Dog, puppy badpuppy baddog!', 'new_string' => '$$$, $$$$$ badpuppy bad$$$!', 'clean' => false
If you wanna do some testing just run
$ phpspec run