faresmts/safewords

a PHP lib for filtering bad words from strings

Installs: 4 185

Dependents: 0

Suggesters: 0

Security: 0

Stars: 8

Watchers: 1

Forks: 0

Open Issues: 0

pkg:composer/faresmts/safewords

v0.1.1 2023-01-03 00:17 UTC

This package is auto-updated.

Last update: 2025-12-06 18:45:55 UTC


README

Safewords is a package that can be used in any PHP framework, calling in a static method and returning the censored text or a boolean to know if is safe.

Support me staring this repository or connecting with me in linkedin

Installation

You can install the package via composer:

composer require faresmts/safewords

Usage

This is the simplest way to call a safewords checker:

$isSafe = SafeWords::filter($text)
            ->isSafe()
            ->get();

And this is the way to call a safewords censor:

$censoredText = SafeWords::filter($text)
                   ->replace()
                   ->get();

Both methods can be called with useDictionary() function to add new words to block:

$isSafe = SafeWords::filter($text)
            ->useDictionary(['foo', 'bar'])
            ->isSafe()
            ->get();

$censoredText = SafeWords::filter($text)
                    ->useDictionary(['foo', 'bar'])
                    ->replace()
                    ->get();

Functions

  • filter(string $text): add the text you want to check.

  • useDictionary(array $userBadWords): add the words you want to block in SafeWords checker.

  • isSafe(): method that evaluates whether the text is safe.

  • replace(string $replace = '*'): method that replaces each character of the bad word with the variable inside $string. Default is '*'.

  • get(): get the result of the chosen method.

Exceptions

  • The methods isSafe() and replace() cannot be called at the same time, throwing an exception if this happens.

  • The method useDictionary() cannot be called after the isSafe() or replace(). It must be called before.