PHPackages                             tbetool/spam-doctor - 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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. tbetool/spam-doctor

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

tbetool/spam-doctor
===================

Prevent your email from being spammed. PHP Library to check for whether content contains spam words.

1.3.0(7y ago)82244PHPPHP &gt;=5.5

Since Oct 11Pushed 7y ago1 watchersCompare

[ Source](https://github.com/TBETool/spam-doctor)[ Packagist](https://packagist.org/packages/tbetool/spam-doctor)[ Docs](http://thebornengineer.com)[ RSS](/packages/tbetool-spam-doctor/feed)WikiDiscussions master Synced today

READMEChangelog (4)DependenciesVersions (4)Used By (0)

PHP Library: Spam Doctor
------------------------

[](#php-library-spam-doctor)

Check your email content for spam possibilities before being spammed. PHP Library to check if content contains spam words.

---

### Using the Library

[](#using-the-library)

#### Installation

[](#installation)

Intall library in PHP project using composer

```
composer require tbetool/spam-doctor

```

#### Using Library

[](#using-library)

```
$spamDoctor = new SpamDoctor();

$spamDoctor->check($text_content);

```

#### `check()` parameters

[](#check-parameters)

1. **text\_content**: Text content to check for spam. You can pass both plain text and html content
2. **is\_html** *(boolean)*: if **text\_content** is **HTML**, set second parameter to **true**. *Default: false*.

#### Get output

[](#get-output)

```
$spamDoctor->getSpamItems();
```

returns array of spam keyword and their count of occurrences.

```
[
   0 => [
     item => 'welcome',
     count => 4
   ]
]
```

---

```
$spamDoctor->getSpamPositions();
```

returns array of positions of the spam items in ascending order.

```
[
   0 => 4,
   1 => 12,
   2 => 25
]
```

---

```
$spamDoctor->getHighlighted();
```

returns complete string with spam keywords highlighted in red color. If HTML content is provided to check, this will return only the text of the HTML content.
To get HTML content highlighted, pass **true** as parameter.

---

```
$spamDoctor->getHighlighted(true);
```

returns complete HTML content with spam keywords highlighted.

---

```
$spamDoctor->getSpamDictionary();
```

returns array of complete list of words used to detect spam contents.

---

### Replace Rule

[](#replace-rule)

Library also support replace rule which can be used to replace spamming text on the go. You can pass json rule in key-value pair where key in the spam text is replaced by the corresponding value.

To set the replace rule, use following function before calling `check()`

```
$replace_rule = [
    'o' => 0,
    'O' => 0,
    '*' => '_'
];

$replace_rule = json_encode($replace_rule);

$spamDoctor->setReplaceRule($replace_rule);
```

Above example will replace **o** and **O** (upper and lowercase of O) with 0 (zero)

You can also pass common letter to replace with if letter in `replace_rule` is not found by passing `*` key with appropriate value.

For example, in above example if a spam word contains **o** or \**O* will be replaced with 0 otherwise will add **\_** (underscore) to random place in the word.

---

### Self Learning

[](#self-learning)

This library learns itself as it processes the spam contents. It generates a dictionary file in **data** directory name **spam\_data.txt**.

You can also teach the doctor by passing json data to the `teachDoctor()` function.

```
$spamDoctor->teachDoctor($json_data);
```

**NOTE**: Json data can be upto 2-Dimensional array

---

### Exception Handling

[](#exception-handling)

*Ex:*

```
try {
    $spamDoctor->check($html_content, true);
} catch (Exception $exception) {
    echo $exception->getMessage();
}

```

---

### Bug Reporting

[](#bug-reporting)

If you found any bug, create an [issue](https://github.com/TBETool/spam-doctor/issues/new).

---

### Support and Contribution

[](#support-and-contribution)

Something is missing?

- `Fork` the repositroy
- Make your contribution
- make a `pull request`

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 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 ~3 days

Total

3

Last Release

2764d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/6560085?v=4)[Anuj Sharma](/maintainers/anuj9196)[@anuj9196](https://github.com/anuj9196)

---

Top Contributors

[![anuj9196](https://avatars.githubusercontent.com/u/6560085?v=4)](https://github.com/anuj9196 "anuj9196 (7 commits)")

---

Tags

Anuj SharmaTBEAnuj TBEspam checkerPHP download from urlspam doctorphp spam detectorphp spam checkerspam detectorphp spam doctoremail spam checkphp check email spamcheck if email content is spamcheck if email contains spam wordsbest spam doctoremail spamphp email checkvalidate spam content

### Embed Badge

![Health badge](/badges/tbetool-spam-doctor/health.svg)

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

###  Alternatives

[webmozart/assert

Assertions to validate method input/output with nice error messages.

7.6k894.0M1.2k](/packages/webmozart-assert)[swaggest/json-schema

High definition PHP structures with JSON-schema based validation

48612.5M73](/packages/swaggest-json-schema)[stevebauman/purify

An HTML Purifier / Sanitizer for Laravel

5325.6M19](/packages/stevebauman-purify)[ashallendesign/laravel-config-validator

A package for validating your Laravel app's config.

217905.3k5](/packages/ashallendesign-laravel-config-validator)[crazybooot/base64-validation

Laravel validators for base64 encoded files

1341.9M8](/packages/crazybooot-base64-validation)[xemlock/htmlpurifier-html5

HTML5 support for HTML Purifier

1052.9M11](/packages/xemlock-htmlpurifier-html5)

PHPackages © 2026

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