PHP code example of tscheckenbach / php-bad-words

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

    

tscheckenbach / 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.


  array(
    array("ass","among"), // rule: among
    "anal",               // rule: alone
    "beastiality",        // rule: alone
    "fart",               // rule: alone
    array("vag","among")  // rule: among
  );

  $myDictionary = array(
    array("ass","among"),
    "butt"
  );
  $bad = new PhpBadWords();
  $obj->setDictionaryFromArray( $myDictionary );

  /*
  // dictionary.php
  
    return array(
      array("ass","among"),
      "anal",
      "butt"
    );
  */
  $bad = new PhpBadWords();
  $obj->setDictionaryFromFile( __DIR__ . "/dictionary.php" );

"expalmer/php-bad-words": "dev-master",