Filters through text and cleans the input of bad words found.
Pull in the composer package by running the command below:
composer require oliveris/bad-words
Import the BadWords namespace into the class (autoloading)
use BadWords\BadWords;
Below is an example that returns a bool value if a bad word was detected within the given string.
BadWords::checkForBadWords($test_string)
Below is an example that returns an array value of bad words was detected within the given string.
BadWords::getBadWords($test_string)
Below is an example that returns a clean string, it replaces any bad words found within a string with random words that the user has set.
BadWords::setReplacementWords([
'hello',
'world',
'tree',
'desk',
'computer'
]);
BadWords::replaceBadWords($test_string);
Below is an example that returns a clean string, it replaces any bad words found with a mask the same length as the bad words.
BadWords::maskBadWords($test_string)
Below is an example that returns the string in its original unmasked form.
BadWords::unMaskBadWords($masked_string);
BadWords::setFilterWords([
'moody',
'fat',
'cunt'
]);
BadWords::addToFilterWords([
'bollocks',
'shit',
'slag'
]);
BadWords is open-sourced software licensed under the MIT license.