Download the PHP package orionstar/bad-word-filter without Composer
On this page you can find all versions of the php package orionstar/bad-word-filter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Table of contents
Download orionstar/bad-word-filter
More information about orionstar/bad-word-filter
Files in orionstar/bad-word-filter
Download orionstar/bad-word-filter
More information about orionstar/bad-word-filter
Files in orionstar/bad-word-filter
Vendor orionstar
Package bad-word-filter
Short Description Dependency free PHP bad word filtering. Checks for the existence of a bad word in a string or array.
License MIT
Package bad-word-filter
Short Description Dependency free PHP bad word filtering. Checks for the existence of a bad word in a string or array.
License MIT
Please rate this library. Is it a good library?
Informations about the package bad-word-filter
BadWordFilter
A bad word filter for dependency free PHP. Pass in a string or multidimensional array to check for the existence of a predefined list of bad words. Use the list that ships with the application or define your own custom blacklist. BadWordFilter only matches whole words (excluding symbols) and not partial words. This will match:
but this will not:
QuickStart Guide
1) add the following to your composer.json file:
2) Run composer install
3) Add BadWordFilter to your use list
4) start cleaning your inputs~
INPORTANT NOTE
BadWordFilter does not and never will prevent XSS or SQL Injection. Take the proper steps in your code to sanitize all user input before
storing to a database or displaying to the client.
Settings options
BadWordFilter takes 3 options:
Source Types
File
If you specify a source type of "file" you must also specify a source_file or use the default source file included with this package.
The Source File must return an array of words to check for.
Array
If you specify a source type of "array" you must also specify a "bad_words_array" key that contains a list of words to check for.
Also Check
In addition to the default list specified in the config file or array you can also pass in an "also_check" key that contains an array of words
to flag.
Overriding Defaults
You can override the default settings in the constructor if using the class as an instance, or as an optional parameter in the static method call
How to handle bad words
By default bad words will be replaced with the first letter followed by the requisite number of asterisks and then the last letter. Ie:
"Cheese" would become "C****e"
This can be changed to be replaced with a set string by passing the new string as an argument to the "clean" method
or
In case you want to keep bad word and surround it by anything (ex. html tag):
Full method list
isDirty
Check if a string or an array contains a bad word
Params:
$input - required - array|string
Return:
Boolean
Usage:
clean
Clean bad words from a string or an array. By default bad words are replaced with asterisks with the exception of the first and last letter.
Optionally you can specify a string to replace the words with
Params:
$input - required - array|string
$replaceWith - optional - string
Return:
Cleaned array or string
Usage:
STATIC clean
Static wrapper around the "clean" method.
Params:
$input - required - array|string
$replaceWith - optional - string
$options - optional - array
Return:
Cleaned array or string
Usage:
getDirtyWordsFromString
Return the matched dirty words
Params:
$input - required - string
Return:
Boolean
Usage:
getDirtyKeysFromArray
After checking an array using the isDirty method you can access the bad keys by using this method
Params : none
Return:
String - dot notation of array keys
Usage:
Settings options
BadWordFilter takes 3 options:Source Types
File If you specify a source type of "file" you must also specify a source_file or use the default source file included with this package. The Source File must return an array of words to check for. Array If you specify a source type of "array" you must also specify a "bad_words_array" key that contains a list of words to check for.Also Check
In addition to the default list specified in the config file or array you can also pass in an "also_check" key that contains an array of words to flag.Overriding Defaults
You can override the default settings in the constructor if using the class as an instance, or as an optional parameter in the static method callHow to handle bad words
By default bad words will be replaced with the first letter followed by the requisite number of asterisks and then the last letter. Ie: "Cheese" would become "C****e" This can be changed to be replaced with a set string by passing the new string as an argument to the "clean" method or In case you want to keep bad word and surround it by anything (ex. html tag):Full method list
isDirty
Check if a string or an array contains a bad word Params: $input - required - array|string Return: Boolean Usage:clean
Clean bad words from a string or an array. By default bad words are replaced with asterisks with the exception of the first and last letter. Optionally you can specify a string to replace the words with Params: $input - required - array|string $replaceWith - optional - string Return: Cleaned array or string Usage:STATIC clean
Static wrapper around the "clean" method. Params: $input - required - array|string $replaceWith - optional - string $options - optional - array Return: Cleaned array or string Usage:getDirtyWordsFromString
Return the matched dirty words Params: $input - required - string Return: Boolean Usage:getDirtyKeysFromArray
After checking an array using the isDirty method you can access the bad keys by using this method Params : none Return: String - dot notation of array keys Usage:All versions of bad-word-filter with dependencies
PHP Build Version
Package Version
Requires
php Version
>=7.4
The package orionstar/bad-word-filter contains the following files
Loading the files please wait ....