PHP code example of jcrowe / bad-word-filter

1. Go to this page and download the library: Download jcrowe/bad-word-filter 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/ */

    

jcrowe / bad-word-filter example snippets


$myString = "Don't be a #FOOBAR!";
$clean = BadWordFilter::clean($myString);
var_dump($clean);
// output: "Don't be a #F****R!"

$myString = "I am an ASSociative professor";
$clean = BadWordFilter::clean($myString);
var_dump($clean);
// output: "I am an ASSociative professor"

$providers = array(
   ...
   ...
   'JCrowe\BadWordFilter\Providers\BadWordFilterServiceProvider',
),

$aliases = array(
    ...
    ...
    'BadWordFilter'	  => 'JCrowe\BadWordFilter\Facades\BadWordFilter',
),

$cleanString = BadWordFilter::clean("my cheesy string");
var_dump($cleanString);
// output: "my c****y string"

$options = array(
    'source' => 'file',
    'source_file' => __DIR__ . '/bad_words.php',
    'strictness' => 'very_strict',
    'also_check' => array(),
);

$myOptions = array('strictness' => 'permissive', 'also_check' => array('foobar'));
$filter = new \JCrowe\BadWordFilter\BadWordFilter($myOptions);

$cleanString = $filter->clean('Why did you FooBar my application?');
var_dump($cleanString);
// output: "Why did you F****r my application?"

$myOptions = array('also_check' => array('cheesy'));
$cleanString = BadWordFilter::clean("my cheesy string", '#!%^", $myOptions);
var_dump($cleanString);
// output: "my #!%^ string"

$myOptions = array('also_check' => array('cheesy'));
$filter = new \JCrowe\BadWordFilter\BadWordFilter($myOptions);
$cleanString = $filter->clean("my cheesy string", "#!$%");
var_dump($cleanString);
// output: "my #!$% string"

$myOptions = array('also_check' => array('cheesy'));
$filter = new \JCrowe\BadWordFilter\BadWordFilter($myOptions);
$cleanString = $filter->clean("my cheesy string", '<span style="color: red;">$0</span>');
var_dump($cleanString);
// output: "my <span style="color: red;">cheesy</span> string"

$filter = new \JCrowe\BadWordFilter\BadWordFilter();

if ($filter->isDirty(array('this is a dirty string')) {
    /// do something
}

$filter = new \JCrowe\BadWordFilter\BadWordFilter();
$string = "this really bad string";
$cleanString = $filter->clean($string);

$string = "this really bad string";
$cleanString = BadWordFilter::clean($string);

$filter = new \JCrowe\BadWordFilter\BadWordFilter();
if ($badWords = $filter->getDirtyWordsFromString("this really bad string")) {
    echo "You said these bad words: " . implode("<br />", $badWords);
}

$arrayToCheck = array(
    'first' => array(
        'bad' => array(
            'a' => 'This is a bad string!',
            'b' => 'This is a good string!',
        ),
    ),
    'second' => 'bad bad bad string!',
);

$filter = new \JCrowe\BadWordFilter\BadWordFilter();

if ($badKeys = $filter->getDirtyKeysFromArray($arrayToCheck)) {

    var_dump($badKeys);
    /* output:

        array(
            0 => 'first.bad.a',
            1 => 'second'
        );
    */
}