1. Go to this page and download the library: Download expalmer/php-bad-words library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
expalmer / php-bad-words example snippets
/* Using Composer */
rds\PhpBadWords as BadWords;
$myDictionary = array(
array("ass","among"),
"anal",
"butt"
);
$myText = "You are an asshole";
$badwords = new BadWords();
$badwords->setDictionaryFromArray( $myDictionary )
->setText( $myText );
var_dump( $badwords->check() );
// output: TRUE.
// Because the dictionary has a word `ass` with `among` rule.
var_dump( $badwords->checkAlone() );
// output: FALSE.
// Because now it verified by word `ass` alone, and it does not exist alone.
// ( It ignores dictionary word rules )
var_dump( $badwords->checkAmong() );
// output: TRUE.
// Again, it verified by `ass` among each word in the text.
// ( It ignores dictionary word rules )
// WITH THE WORD `anal`
$myAnotherText = "She is not a research analyst";
$badwords->setText( myAnotherText );
var_dump( $badwords->check() );
// output: FALSE.
var_dump( $badwords->checkAlone() );
// output: FALSE.
var_dump( $badwords->checkAmong() );
// output: TRUE.