PHPackages                             tscheckenbach/php-bad-words - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. tscheckenbach/php-bad-words

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

tscheckenbach/php-bad-words
===========================

PHP Bad words filtering. Checks for existence of bad word in a string but checks too an alone word or among the string

0.1.3(10y ago)027MITPHPPHP &gt;=5.3.0

Since Jun 3Pushed 10y ago1 watchersCompare

[ Source](https://github.com/tscheckenbach/php-bad-words)[ Packagist](https://packagist.org/packages/tscheckenbach/php-bad-words)[ RSS](/packages/tscheckenbach-php-bad-words/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (1)Versions (5)Used By (0)

PHP Bad Words
-------------

[](#php-bad-words)

PHP BAD WORDS is a PHP Package that return TRUE or FALSE when it finds a bad word in a text.

The cool thing is that you can put rules in each word of the dictionary.

Explanation
-----------

[](#explanation)

1. **Alone**: If the text is `You are a Asshole`, and the dictionary has the bad words `array( 'ass' );`it doesn't match, because the word `ass` must be appears alone.
2. **Among**: The same text `You are a Asshole` and the same word, but now as an array with a rule `array( array('ass','among') );`, now it matches because the rule `among`. It will find among each word of the text by the word `ass`, and the word `asshole` has the word `ass`, got it ;).

Installing
----------

[](#installing)

To install include it in your projects's `composer.json`.

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

There are no additional dependencies required for this package to work.

Usage
-----

[](#usage)

```
  /* Using Composer */
  require_once 'vendor/autoload.php';
  use \Expalmer\PhpBadWords\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.
```

Setting the Dictionary
----------------------

[](#setting-the-dictionary)

#### How the dictionary looks like.

[](#how-the-dictionary-looks-like)

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

### By an Array

[](#by-an-array)

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

### By a File

[](#by-a-file)

```
  /*
  // dictionary.php
