Download the PHP package consoletvs/profanity without Composer
On this page you can find all versions of the php package consoletvs/profanity. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download consoletvs/profanity
More information about consoletvs/profanity
Files in consoletvs/profanity
Package profanity
Short Description PHP library to block bad words in a string
License MIT
Informations about the package profanity
Profanity
What is Profanity?
Profanity is a PHP library that allows blocking bad words out of a given string. It currently blocks more than 2.555 words in different languages. It's very easy to use and can filter a 100 chars string in about 0.0021 seconds!
Sample Filter
This example is a simple string that is going to be filtered using this library.
Documentation
Installation
First, require it using composer:
Laravel
To install it on laravel, simply add the service provider and the alias in :
Service Provider:
Alias (optional):
Usage
PHP
Laravel
Methods
Constructor
-
blocker($text, $blocker = '****', $languages = [])
Setup the text and the blocker to use.
note: The blocker defaults to
note: Pass language codes to reduce the list of bad words that are taken into account.
Class Methods
-
strict(true/false)
Set the strict mode to enabled or disabled. Strict mode replaces the string even if it's not a word: assets => (tagged as ass) => Disable to ensure normal usage. Defaults to false.
-
strictClean(true/false)
Set the strict clean mode to enabled or disabled. Strict clean mode ensures the first blocked character is repeated for each bad word character. If so, a bad word of length = 3 (ass) will result in a , instead of the blocker (defaults to ). If the blocker is then the same example as above would produce as strict clean true and as false. Defaults to true.
-
clean()
Returns true if the text have no bad words on it.
-
filter()
Filters the text with the given blocker.
-
badWords()
Return the bad words found in the text.
-
text($text)
Sets the text to filter.
-
blocker($blocker)
Sets the string that will replace the bad words.
-
dictionary($dictionary)
Sets the dictionary. If string is provided, it will be treated as a path and will try to decode the json contained in the path. If array is provided, it will set the dictionary.
Example dictionary: