Giter Club home page Giter Club logo

badword-filter's Introduction

Badwords PHP

Badwords PHP is small lightweight PHP library for detecting "bad" words, e.g. profanity, in content.

Aside from the obvious matching if a word is present in a string, the filter also tries to detect words similar to those in the list, e.g. gl@d and glad.

The library is designed to be highly configurable, from the word lists used to the character replacement configuration at the heart of the filter.

Note: At present the default configuration provided is not a bulletproof/catch-all solution, but it will catch most variations. This will become more robust over time.

Requirements

  • The library is only supported on PHP 5.3.0 and up.
  • It has been assumed an autoloader will be present. If you require one, you can find one here.

Installation

Simply download the library and add the src folder to your project.

Usage

The simplest way to use the library is as follows,

$dictionary = new \Badword\Dictionary\Php('path/to/dictionary_list.php');
$config = new \Badword\Filter\Config\Standard();
$filter = new \Badword\Filter($dictionary, $config);

$result = $filter->filter('My content...');
$result->getRiskLevel();
$result->getMatches();
$result->getMatchesAndRiskLevels();
$result->getHighlightedContent();

Explained,

  • First load your list of "bad" words using the Dictionary objects, or create your own and implement the Dictionary interface.
  • Define a configuration for the filter to use (a default Standard configuration is provided).
  • Create the Filter passing your dictionary(s) and config.
  • Filter your content using the filter() method.
  • Use the Result object to analyse your content.

Testing

To run the tests, make sure you have PHPUnit 3.5.0 and up installed, and just run the following in the project root,

phpunit

Credits

badword-filter's People

Contributors

stephenmelrose avatar

Watchers

Kevin E Ogbonna avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.