dev-master
9999999-devBadwords PHP is a small lightweight PHP library for detecting 'bad' words, e.g. profanity, in content.
MIT
The Requires
- php >=5.3
The Development Requires
by mioga-brian
by stephenmelrose
badwords
Badwords PHP is a small lightweight PHP library for detecting 'bad' words, e.g. profanity, in content.
Badwords PHP is small lightweight PHP library for detecting "bad" words, e.g. profanity, in content., (*1)
Aside from the obvious matching if a word is present in a string, the filter also tries to detect words similar to those in the list, e.g. gl@d
and glad
., (*2)
The library is designed to be highly configurable, from the word lists used to the character replacement configuration at the heart of the filter., (*3)
Note: At present the default configuration provided is not a bulletproof/catch-all solution, but it will catch most variations. This will become more robust over time., (*4)
To install include it in your projects's composer.json
., (*5)
$ composer require mioga-brian/badwords-php $ composer update
There are no additional dependencies required for this package to work., (*6)
The simplest way to use the library is as follows,, (*7)
$dictionary = new \Badword\Dictionary\Php('path/to/dictionary_list.php'); $config = new \Badword\Filter\Config\Standard(); $filter = new \Badword\Filter($dictionary, $config); $result = $filter->filter('My content...'); $result->getRiskLevel(); $result->getMatches(); $result->getMatchesAndRiskLevels(); $result->getHighlightedContent();
Explained,, (*8)
Dictionary
objects, or create your own and implement the Dictionary
interface.Standard
configuration is provided).Filter
passing your dictionary(s) and config.filter()
method.Result
object to analyse your content.// An example moderate dictionary. $dictionaryWords = array( 'some', 'bad', 'words' ); $dictionary = new \Badword\Dictionary\PhpArray($dictionaryWords, 1); $config = new \Badword\Filter\Config\Standard(); $filter = new \Badword\Filter($dictionary, $config); $result = $filter->filter('My content...'); $result->getRiskLevel(); $result->getMatches(); $result->getMatchesAndRiskLevels(); $result->getHighlightedContent();
$dictionaryWords = array( 'reject' => array( 'maecenas', 'mauris', 'luctus' ), 'moderate' => array( 'consectetur', 'neque', 'velit' ) ); $Badwords = new \Badword\Badwords($dictionaryWords); $result = $Badwords->Filter()->filter('My content...')); $result->getRiskLevel(); $result->getMatches(); $result->getMatchesAndRiskLevels(); $result->getHighlightedContent();
To run the unit tests on this package, simply run vendor/bin/phpunit
from the package directory., (*9)
Badwords PHP is a small lightweight PHP library for detecting 'bad' words, e.g. profanity, in content.
MIT
badwords