PHPackages                             gorankrgovic/spam-marker - 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. gorankrgovic/spam-marker

ActiveLibrary

gorankrgovic/spam-marker
========================

An extensible, simple yet powerful spam filter library

1.1.0(8y ago)0177↓100%MITPHPPHP &gt;=5.3.0

Since May 26Pushed 8y ago1 watchersCompare

[ Source](https://github.com/gorankrgovic/spam-marker)[ Packagist](https://packagist.org/packages/gorankrgovic/spam-marker)[ RSS](/packages/gorankrgovic-spam-marker/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (4)Used By (0)

SpamMarker PHP library
----------------------

[](#spammarker-php-library)

SpamMarker is a simple library for detecting spam in provided strings. It follows the open closed principle by introducing Spam Filters which are just separate classes used to extend the SpamMarker detecting capabilities.

The original idea, and actually a slightly different library, is from a lib called Spam Filter by Laju Morrison, which you can find [here](https://github.com/morrelinko/spam-detector).

I was just tired of all sorts of spam which comes from the user input on my projects, so I finally created this.

Instalation
-----------

[](#instalation)

This library can be loaded into your projects using [Composer](http://getcomposer.org) or by re-inventing the wheel and creating your own autoloader.

Instalation via composer:

```
 composer require gorankrgovic/spam-marker

```

Setup and basic usage
---------------------

[](#setup-and-basic-usage)

This should be done once throughout the app.

```
use SpamMarker\SpamMarker;

// 1.
// Use some filters
use SpamMarker\Filter\BlackListed;

// 2.
// Initalize the blackisted filter
$blackListed = new BlackListed();

// Add some spammy keywords
$blackListed->add('hacker');
$blackListed->add('attacker');

// 3.
// Initialize the spam marker
$spamMarker = new SpamMarker();

// 4.
// Register the filters
$spamMarker->registerFilter($blackListed);

// 5.
// Check your string against filters
$spamMarkerResult = $spamMarker->check("
	Hello, this is some text containing hacker and attacker
	and should fail as it has a word that is black-listed
");

// var_dump ( $spamMarkerResult );
// It gives you two objects - is_spam (bool) and messages array

if ( $spamMarkerResult->passed() )
{
    // Do some stuff, because the spam marker is passed
    echo 'Your string doesn\'t contain the spam';
}
else
{
    echo 'String containts the spam!';
}

// If you only want to see if it's failed then just...
if ( $spamMarkerResult->failed() ) {
    // Do stuff
}
```

Each time you call the `check()` method on a string, it returns a `SpamOutput`Object which holds the spam check result and messages.

You can change various stuff inside such as messages for each filter. with two methods:

Calling setOption function:

```
$loadedFilter->setOption('message', 'My own returning error message');
```

Or by initializing with different config

```
$config = array(
    'message' => 'My own custom error message'
);

$blackListed = new BlackListed($config);
```

Currently provided filters
--------------------------

[](#currently-provided-filters)

###### 1. BlackListed Filter:

[](#1-blacklisted-filter)

The black list detector flags a string as a spam if it contains any of one or more words that has been added to the black list. Strings could be formed from Regular Expressions or a Character Sequence.

###### 2. BlackListedFile Filter:

[](#2-blacklistedfile-filter)

This one is similar to the above but it fetches regex'es and string from provided folder. Currently the folder is in `src/Filter/blacklists`. If you want to provide your own files, upon init you must declare the folder path:

```
$config = array(
    'dir' => '/path/to/your/folder'
);

$blackListedFile = new BlackListedFile($config);
```

Please DO NOT forget to add the `index` file which contains the filenames within the provided directory.

###### 3. TooManyEmails Filter:

[](#3-toomanyemails-filter)

The name says it all. It matches the number of links in string. It's configurable easy like:

```
$config = array(
    'emailsAllowed' => 2
);
```

###### 4. TooManyLinks Filter:

[](#4-toomanylinks-filter)

How many links we can allow in the string

```
$config = array(
    'linksAllowed' => 2,
    'linksRatio' => 20 // Percentage of links to words ratio within the text
);
```

###### 5. TooManyPhones Filter:

[](#5-toomanyphones-filter)

How many phone numbers we can allow.

```
$config = array(
    'phonesAllowed' => 2
);
```

###### 6. TooManyUppercase Filter:

[](#6-toomanyuppercase-filter)

How many uppercase words are allowed in string. Useful when someones enter the `FREE FREE BLAH BLAH DISCOUNT OFF`.

```
$config = array(
    'wordsRatio' => 20 // Percentage of allowed uppercase words in a string
);
```

Creating your own custom Filter
-------------------------------

[](#creating-your-own-custom-filter)

You create a detector simply by creating a class that implements the `FilterInterface`which defines the following contract.

```
interface FilterInterface
    {
        public function filter($data);
    }
```

Your filter must return an array of:

```
array(
    'founded' => true, // or false if spam not found
    'message' => 'message to return if spam found'
);
```

After creating your own filter, you add it using the `registerFilter()` method in the SpamMarker.

License
-------

[](#license)

The MIT License (MIT). Please see LICENSE for more information.

Voila!

###  Health Score

27

—

LowBetter than 51% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

3

Last Release

3223d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/dc897661efd3f9b1d0b6cee6fa6eb2f5535819e0c2e0a0adab66b4d6002133be?d=identicon)[gorankrgovic](/maintainers/gorankrgovic)

---

Top Contributors

[![gorankrgovic](https://avatars.githubusercontent.com/u/12137730?v=4)](https://github.com/gorankrgovic "gorankrgovic (6 commits)")

### Embed Badge

![Health badge](/badges/gorankrgovic-spam-marker/health.svg)

```
[![Health](https://phpackages.com/badges/gorankrgovic-spam-marker/health.svg)](https://phpackages.com/packages/gorankrgovic-spam-marker)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
