Giter Site home page Giter Site logo

booleanbridge / profanity_php Goto Github PK

View Code? Open in Web Editor NEW
6.0 1.0 0.0 453 KB

An open-source PHP profanity filter.

License: Creative Commons Zero v1.0 Universal

PHP 99.93% Shell 0.07%
php profanity profanity-check profanity-detection profanity-filter profanityfilter

profanity_php's Introduction

Profanity PHP ๐Ÿš€

CodeFactor GitHub License GitHub Repo stars Cost Effort Lines

Welcome to Profanity PHP, the vibrant library designed to keep your text sparkling clean! ๐ŸŒŸ This lightweight and efficient tool is your go-to solution for detecting profanity in text using a comprehensive list of naughty words from List of Dirty, Naughty, Obscene, and Otherwise Bad Words.

Table of Contents ๐Ÿ“œ

Features ๐ŸŒˆ

  1. Detect profane words in a string using a comprehensive list of profane words as a Hash Table.
  2. Uncover naughty phrases in a string using a comprehensive list of profane phrases. This uses the Boyer-Moore algorithm to find phrases, treating each word as a character.

Getting Started ๐Ÿš€

These instructions will help you set up the library in your project.

Prerequisites ๐Ÿ› ๏ธ

Ensure you have the following installed:

  • PHP 7.4 or higher
  • Git

Installation ๐Ÿšš

  1. Clone the repository or add it as a submodule to your project.

    git clone https://github.com/friendshipking/profanity_php.git
    # OR
    git submodule add https://github.com/friendshipking/profanity_php.git
  2. Follow these instructions if there is a new commit in the List-of-Dirty-Naughty-Obscene-and-Otherwise-Bad-Words_V2:

    • Run the step_1.php to create the languages directory and files.
    • Run the step_2.php to create the countryToSupportedLanguageCodes array.
    • Run the step_3.php to list all the three-letter codes that are not added to the countryToSupportedLanguageCodes array. If there is no output, you are good to go. Otherwise:
    • Use the AI prompt inside three_letter_codes.php file to generate the array. Replace the existing array in the file. If Bing is unable to get the language, use this link to get the language code. After adding the array, run step_2.php again.
    • All required files are successfully generated.
    • Test the setup by running the test.php file.
    • Commit the changes and create a pull request to the main repo. This ensures that the library is up to date with the latest changes in List-of-Dirty-Naughty-Obscene-and-Otherwise-Bad-Words_V2.

Usage ๐Ÿ› ๏ธ

Include the library in your project and let the magic begin! ๐Ÿง™ Refer to the code comments for detailed information on each function.

include 'profanity_php/main.php';

Function โš™๏ธ

isProfanity(&$text, $detectedLanguages = [], &$exploded = [], &$explodedLength = 0, $all = false): bool

Check if a string contains profanity.

  • $text: The string to check. Optional, If not provided, then $exploded must be provided.
  • $detectedLanguages: An array of detected languages. Optional. Languages are automatically detected based on the user's country (using HTTP_CF_IPCOUNTRY header from Cloudflare) , ACCEPT_LANGUAGE header if this is not set.
  • $exploded: The exploded and cleaned string to remove punctuations and emojis. Optional. If you are already creating an exploded string, pass it to the function to avoid creating it again. If not provided, then $text must be provided.
  • $explodedLength: The length of the exploded string. Optional. Must be provided if $exploded is provided.
  • $all: If true, check for all available languages. Optional. When set, all the languages are checked for profanity. If false, only the languages in $detectedLanguages or auto-detected languages are checked.

Global Variables ๐ŸŒ

When you include this file, the following global variables are available:

  1. $supportedLanguages: After the function isProfanity() is called, it will contain all the language the profanity in the text was checked for.

Contribution ๐Ÿค

Join the community and contribute to the project by submitting issues or pull requests. Your positivity and contributions are always welcome! ๐ŸŽ‰

License ๐Ÿ“œ

This project is licensed under the Creative Commons Zero v1.0 Universal - see the LICENSE file for details.

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.