PHPackages                             joetannenbaum/mr-clean - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. joetannenbaum/mr-clean

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

joetannenbaum/mr-clean
======================

0.1.0(11y ago)23044.5k10MITPHPPHP &gt;=5.4.0

Since Sep 11Pushed 11y ago10 watchersCompare

[ Source](https://github.com/joetannenbaum/mr-clean)[ Packagist](https://packagist.org/packages/joetannenbaum/mr-clean)[ RSS](/packages/joetannenbaum-mr-clean/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (3)Used By (0)

Mr. Clean
=========

[](#mr-clean)

[![Latest Version](https://camo.githubusercontent.com/d7bf15a88be00f7f45cd392a5c38fd76273590215fcf3096c9c418868eb7cf76/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f6a6f6574616e6e656e6261756d2f6d722d636c65616e2e7376673f7374796c653d666c6174)](https://github.com/joetannenbaum/mr-clean/releases)[![Software License](https://camo.githubusercontent.com/f251623e510f5909f16ae3f4e6e548dac11340b9fde1a99be26b015b39272c00/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c6174)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/e0f5ee449ac038387d505ffc0735700abd19f7a4651d5617a4be1545b3d425ee/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6a6f6574616e6e656e6261756d2f6d722d636c65616e2f6d61737465722e7376673f7374796c653d666c6174)](https://travis-ci.org/joetannenbaum/mr-clean)[![Coverage Status](https://camo.githubusercontent.com/c327d94f3373a13c453fbb13257e16ca130bd022616415ceb565e68de6dab16c/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f6a6f6574616e6e656e6261756d2f6d722d636c65616e2e7376673f7374796c653d666c6174)](https://scrutinizer-ci.com/g/joetannenbaum/mr-clean/code-structure)[![Quality Score](https://camo.githubusercontent.com/8fafb3d3c0b2a93f5f90f34fa94c587f06895478cf307bf0a4173e4ce6986982/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6a6f6574616e6e656e6261756d2f6d722d636c65616e2e7376673f7374796c653d666c6174)](https://scrutinizer-ci.com/g/joetannenbaum/mr-clean)[![Total Downloads](https://camo.githubusercontent.com/cc78ad25c68048f2aa7e3fe5ea146c30143d4f0931276690dac0885771e590ac/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a6f6574616e6e656e6261756d2f6d722d636c65616e2e7376673f7374796c653d666c6174)](https://packagist.org/packages/joetannenbaum/mr-clean)

Mr. Clean is an extendible PHP cleaner that allows you to easily clean up strings, arrays, objects, and anything in between.

Table of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Basic Usage](#basic-usage)
- [Scrubbers](#scrubbers)
- [Pre/Post](#prepost)
- [What Can Be Cleaned](#what-can-be-cleaned)
- [Cleaning Specific Keys](#cleaning-specific-keys)
- [Available Scrubbers](#available-scrubbers)
    - [Boolean](#boolean)
    - [HTML](#html)
    - [Strip CSS Attributes](#strip-css-attributes)
    - [Nullify](#nullify)
    - [Null If Repeated](#null-if-repeated)
    - [Strip Phone Number](#strip-phone-number)
- [Extending](#extending)
    - [Writing a Scrubber](#writing-a-scrubber)
    - [Registering a Scrubber](#registering-a-scrubber)

Installation
------------

[](#installation)

Using [composer](https://packagist.org/packages/joetannenbaum/mr-clean):

```
{
    "require": {
        "joetannenbaum/mr-clean": "~0.0"
    }
}

```

Basic Usage
-----------

[](#basic-usage)

Fire it up like so:

```
require_once 'vendor/autoload.php';

$cleaner = new MrClean\MrClean();
```

Scrubbers
---------

[](#scrubbers)

Scrubbers are the classes and functions that actually do the work, and you can assign as many as you want to clean your object.

```
$scrubbers = [
    'trim',
    'stripslashes',
    'strip_tags',
    'remove_weird_characters',
];

$scrubbed = $cleaner->scrubbers($scrubbers)->scrub('I\'m not that dirty.');
```

Scrubbers should always be passed as an array, and will be run in the order that you specify.

Any single argument string manipulation function can be used. To reference a class, simply convert the StudlyCase to snake\_case. In the example above, `remove_weird_characters` refers to a (fictional) class named `RemoveWeirdCharacters`.

Pre/Post
--------

[](#prepost)

To save some typing, you can set scrubbers to run every time before and after each cleaning:

```
$cleaner->pre(['trim']);
$cleaner->post(['htmlentities']);

// trim will run before each of these, htmlentities after each
$cleaner->scrubbers(['strip_tags'])->scrub('This should be cleaned.')
$cleaner->scrubbers(['remove_weird_characters'])->scrub('So should this.')
```

What Can Be Cleaned
-------------------

[](#what-can-be-cleaned)

Better question: what can't? An array of arrays, a string, an array of objects, a single object, you try it, Mr. Clean will probably be able to clean it. All of the following will work:

```
$scrubbed = $cleaner->scrubbers(['trim'])->scrub('Holy string, Batman.');

$scrubbed = $cleaner->scrubbers(['trim'])->scrub(['Holy', 'array', 'Batman']);

$scrubbed = $cleaner->scrubbers(['trim'])->scrub([
        ['Holy', 'array', 'of', 'arrays', 'Batman'],
        ['Holy', 'array', 'of', 'arrays', 'Batman'],
    ]);

$scrubbed = $cleaner->scrubbers(['trim'])->scrub((object) [
        'first_word'  => 'Holy',
        'second_word' => 'object',
        'third_word'  => 'Batman',
    ]);

$scrubbed = $cleaner->scrubbers(['trim'])->scrub([
        (object) [
            'first_word'  => 'Holy',
            'second_word' => 'array',
            'third_word'  => 'of',
            'fourth_word' => 'objects',
            'fifth_word'  => 'Batman',
        ],
        (object) [
            'first_word'  => 'Holy',
            'second_word' => 'array',
            'third_word'  => 'of',
            'fourth_word' => 'objects',
            'fifth_word'  => 'Batman',
        ],
    ]);

$scrubbed = $cleaner->scrubbers(['trim'])->scrub([
        (object) [
            'first_word'  => 'Holy',
            'second_word' => 'mixed',
            'third_word'  => ['bag', 'Batman'],
        ],
    ]);
```

Cleaning Specific Keys
----------------------

[](#cleaning-specific-keys)

Sometimes you don't want to use the same scrubbers on every key in an object or associative array. No problem. Just let Mr. Clean know which ones to apply where and he'll take care of it:

```
$scrubbers = [
    'first_name' => ['trim'],
    'last_name'  => ['stripslashes', 'htmlentities'],
];

$data = [
    [
        'first_name' => 'Joe ',
        'last_name'  => 'O\'Donnell',
    ],
    [
        'first_name' => ' Harold',
        'last_name'  => 'Frank & Beans',
    ],
];

$scrubbed = $cleaner->scrubbers($scrubbers)->scrub($data);

/*
[
    [
        'first_name' => 'Joe',
        'last_name'  => "O'Donnell",
    ],
    [
        'first_name' => 'Harold',
        'last_name'  => 'Frank &amp; Beans',
    ],
]
*/
```

You can also still specify scrubbers that should run for everything:

```
$scrubbers = [
    'strip_tags',
    'first_name' => ['trim'],
    'last_name'  => ['stripslashes', 'htmlentities'],
    'htmlspecialchars',
];
```

Available Scrubbers
-------------------

[](#available-scrubbers)

Mr. Clean comes with a bevy of pre-built scrubbers you can use:

### Boolean

[](#boolean)

Converts falsey text and anything considered `empty` to `false`, otherwise returns `true`. Falsey text includes (not case sensitive):

- no
- n
- false

```
$movies_seen = [
    'The Dark Knight'   => 'y',
    'The Green Lantern' => 'n',
    'The Avengers'      => 'yes',
];

$scrubbed = $cleaner->scrubbers(['boolean'])->scrub( $movies_seen );

/*
[
    'The Dark Knight'   => true,
    'The Green Lantern' => false,
    'The Avengers'      => true,
];
*/
```

### HTML

[](#html)

Strips tags not on the whitelist, removes empty content tags, and repeated opening or closing tags. The whitelist includes:

- a
- p
- div
- strong
- em
- b
- i
- br
- ul
- ol
- li
- h1
- h2
- h3
- h4
- h5
- h6

```
$dirty = 'Some bad HTML here.Soon to be cleaner.';

$scrubbed = $cleaner->scrubbers(['html'])->scrub( $dirty );

// Some bad HTML here.Soon to be cleaner.
```

### Strip CSS Attributes

[](#strip-css-attributes)

Strips the `style`, `class`, and `id` attributes off of all HTML elements.

```
$dirty = 'This was once bold.';

$scrubbed = $cleaner->scrubbers(['strip_css_attributes'])->scrub($dirty);

// This was once bold.
```

### Nullify

[](#nullify)

If a trimmed string doesn't have any length, null it out:

```
$dirty = [
    'cool',
    'also cool',
    ' ',
    '    ',
];

$scrubbed = $cleaner->scrubbers(['nullify'])->scrub($dirty);

/*
[
    'cool',
    'also cool',
    null,
    null,
];
*/
```

### Null If Repeated

[](#null-if-repeated)

If a string is just a repeated character ('1111111' or 'aaaaaaaaa') and has a length greater than two, null it out:

```
$dirty = [
    '11111111',
    '22',
    'bbbbbbbb',
    '333334',
];

$scrubbed = $cleaner->scrubbers(['null_if_repeated'])->scrub($dirty);

/*
[
    null,
    '22',
    null,
    '333334',
];
*/
```

### Strip Phone Number

[](#strip-phone-number)

Strip a phone number down to just the good bits, numbers and the letter 'x' (for extensions):

```
$dirty = [
    '555-555-5555',
    '(123) 456-7890',
    '198 765 4321 ext. 888',
];

$scrubbed = $cleaner->scrubbers(['strip_phone_number'])->scrub($dirty);

/*
[
    '5555555555',
    '1234567890',
    '1987654321x888',
];
*/
```

Extending
---------

[](#extending)

You can register custom scrubbers with Mr. Clean.

### Writing a Scrubber

[](#writing-a-scrubber)

First, write your class. All you have to do is extend `MrClean\Scrubber\BaseScrubber` which adheres to `MrClean\Scrubber\ScrubberInterface`. There is a single property, `value` available to you. This is the string you will manipulate:

```
namespace Your\Namespace;

use MrClean\Scrubber\BaseScrubber;

class YourCustomScrubber extends BaseScrubber {

    public function scrub()
    {
        return str_replace('!', '.', $this->value);
    }

}
```

And that's it. Now just register your scrubber with Mr. Clean.

### Registering a Scrubber

[](#registering-a-scrubber)

The `register` method will take a string indicating the full path of the class, or an array of class paths.

```
$cleaner->register('Your\Namespace\YourCustomScrubber');
```

Now, go ahead and use it:

```
$dirty = [
    'I need to calm down!',
    'Me too!',
];

$scrubbed = $cleaner->scrubbers(['your_custom_scrubber'])->scrub($dirty);

/*
[
    'I need to calm down.',
    'Me too.',
]
*/
```

###  Health Score

35

—

LowBetter than 79% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity43

Moderate usage in the ecosystem

Community14

Small or concentrated contributor base

Maturity49

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

Unknown

Total

1

Last Release

4258d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8cc9e697c220afa4ac18184d1aaab004e2da9448ac251a74e6031eec48b21601?d=identicon)[joetannenbaum](/maintainers/joetannenbaum)

---

Top Contributors

[![joetannenbaum](https://avatars.githubusercontent.com/u/2702148?v=4)](https://github.com/joetannenbaum "joetannenbaum (35 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/joetannenbaum-mr-clean/health.svg)

```
[![Health](https://phpackages.com/badges/joetannenbaum-mr-clean/health.svg)](https://phpackages.com/packages/joetannenbaum-mr-clean)
```

###  Alternatives

[norkunas/youtube-dl-php

youtube-dl / yt-dlp wrapper for php

512323.2k15](/packages/norkunas-youtube-dl-php)[browner12/helpers

generic helpers

289676.6k7](/packages/browner12-helpers)[kop/yii2-scroll-pager

Infinite AJAX scrolling for Yii2 ListView widget

180706.5k10](/packages/kop-yii2-scroll-pager)[tonysm/importmap-laravel

Use ESM with importmap to manage modern JavaScript in Laravel without transpiling or bundling.

148399.8k1](/packages/tonysm-importmap-laravel)[duncan3dc/fork-helper

Simple class to fork processes in PHP and allow multi-threading

73548.0k4](/packages/duncan3dc-fork-helper)[timothyasp/nova-badge-field

A Laravel Nova field.

58548.0k](/packages/timothyasp-nova-badge-field)

PHPackages © 2026

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