GithubHelp home page GithubHelp logo

himanshugoelnasa / laravel-profanity-filter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from askedio/laravel-profanity-filter

0.0 0.0 0.0 45 KB

A string filter and validator for Laravel.

License: GNU Affero General Public License v3.0

PHP 100.00%

laravel-profanity-filter's Introduction

Build Status StyleCI

Laravel Profanity Filter

Filter profanity, or other bad words, out of a string using Laravels localization feature or with any PHP application and some custom coding.

Installation

composer require askedio/laravel5-profanity-filter

Register in config/app.php.

Register the service providers in Laravel 5.4 or lower to enable the package:

Askedio\Laravel5ProfanityFilter\Providers\ProfanityFilterServiceProvider::class,

Configure

php artisan vendor:publish

You can edit the default list of words to filter along with the settings in config/profanity.php.

replaceWith can also be a string of chars to be randomly chosen to replace with, like '&%^@#'.

You can create your own list of words, per language, in resources/lang/[language]/profanity.php.

Usage

$string = app('profanityFilter')->filter('something with a bad word');

The $string will contain the filtered result.

You can also define things inline

$string = app('profanityFilter')->replaceWith('#')->replaceFullWords(false)->filter('something with a bad word'));

You can also use the profanity filter with Laravels Validation feature:

$request->validate([
    'title' => 'required|profanity|unique:posts|max:255',
]);

Options

  • filter($string = string, $details = boolean) pass a string to be filtered.

    • Enable details to have an array of results returned:
      [
        "orig" => "",
        "clean" => "",
        "hasMatch" => boolean,
        "matched" => []
      ]
  • reset() reset replaceWith and replaceFullWords to defaults.

  • replaceWith(string) change the chars used to replace filtered strings.

  • replaceFullWords(boolean) enable to replace full words, disable to replace partial.

Profanity Filter with PHP

You can also use this package without Laravel.

use Askedio\Laravel5ProfanityFilter\ProfanityFilter;

$config = []; // Data from `resources/config/profanity.php`
$badWordsArray = []; // Data from `resources/lang/[lang]/profanity.php`

$profanityFilter =  new ProfanityFilter($config, $badWordsArray);
$string = $profanityFilter->filter('something with a bad word');

Credits

This package is based on banbuilder.

laravel-profanity-filter's People

Contributors

gcphost avatar wrighter989 avatar prashantidealittechno avatar willystadnick 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.