PHP code example of orionstar / bad-word-filter

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

    

orionstar / 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"

use orionstar\BadWordFilter\BadWordFilter;

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

$options = [
    'source'        => 'file',
    'source_file'   => __DIR__ . '/bad_words.php',
    'also_check'    => [],
];

$myOptions = ['also_check' => ['foobar']];
$filter = new \orionstar\BadWordFilter\BadWordFilter($myOptions);

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

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

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

$myOptions = ['also_check' => ['cheesy']];
$filter = new \orionstar\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 \orionstar\BadWordFilter\BadWordFilter();

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

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

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

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

$arrayToCheck = [
    'first' => [
        'bad' => [
            'a' => 'This is a bad string!',
            'b' => 'This is a good string!',
        ],
    ],
    'second' => 'bad bad bad string!',
];

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

if($badKeys = $filter->getDirtyKeysFromArray($arrayToCheck))
{
    var_dump($badKeys);
    /* output:

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