PHPackages                             dtimofeev/sanitizer - 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. dtimofeev/sanitizer

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

dtimofeev/sanitizer
===================

v1.0.0(6y ago)31MITPHPPHP ^7.1CI failing

Since Jan 19Pushed 6y ago1 watchersCompare

[ Source](https://github.com/dtimofeev/Sanitizer)[ Packagist](https://packagist.org/packages/dtimofeev/sanitizer)[ RSS](/packages/dtimofeev-sanitizer/feed)WikiDiscussions master Synced today

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

About
=====

[](#about)

Simple data sanitization library for PHP 7.1+ without any external library dependencies.

[![Build Status](https://camo.githubusercontent.com/8ab1e9c6f1389357121d0811be29c4181167b26ff242e8a6a805a37f7a49c8f8/68747470733a2f2f7472617669732d63692e6f72672f6474696d6f666565762f53616e6974697a65722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/dtimofeev/Sanitizer)[![codecov](https://camo.githubusercontent.com/352b5286fd4bb6c0e2e199dbdee508deeb90c575a4e6634ddbd294e33902e7b9/68747470733a2f2f636f6465636f762e696f2f67682f6474696d6f666565762f53616e6974697a65722f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/dtimofeev/Sanitizer)

Usage
=====

[](#usage)

```
use Sanitizer\Sanitizer;
use Sanitizer\SanitizerSchema as SS;

// Single element
$processed = Sanitezer::process(true, SS::boolean());

// Complex schema
$processed = Sanitizer::process($input, SS::arr()->schema([
    'id'        => SS::integer()->min(1),
    'nickname'  => SS::string()->alphaNum(),
    'email'     => SS::string()->email(),
    'ip'        => SS::string()->ip(),
    'sex'       => SS::string()->optional('na')->oneOf(['male', 'female', 'na']),
    'favMovies' => SS::arr()->each(
        SS::arr()->schema([
            'title'   => SS::string()->trim()->max(200),
            'release' => SS::date()->format('Y-m-d H:i:s'),
            'tags'    => SS::arr()->unique()->each(
                SS::string()->alphaNum()
            ),
        ])
    ),
]));
```

Aliases
=======

[](#aliases)

Aliases allow for a single definition of commonly used sanitization rules. They can be defined via `SS::createAlias(string $name, SanitizerSchema $schema, bool $persistent = true)` and used as normal schema rules `SS::alias($name)` everywhere, no matter the depth. The `$persistent` parameter indicates if the alias should be preserved after first full validation (single call of `Sanitizer::process(...)`). They can also be destroyed manually via `SS::destroyAlias(string $name)`.

Because of the schemas nature these are also more memory efficient than defining a separate schemas.

##### Example:

[](#example)

```
SS::createAlias('alphaNum', SS::string()->alphaNum());

$processed = Sanitizer::process($input, SS::arr()->schema([
    'nickname'  => SS::alias('alphaNum'),
    'favMovies' => SS::arr()->each(
        SS::arr()->schema([
            'tags' => SS::arr()->unique()->each(SS::alias('alphaNum')),
        ])
    ),
]));
```

Detailed supported methods
==========================

[](#detailed-supported-methods)

### SS::boolean()

[](#ssboolean)

methodparamsdescription`optional``?bool $default`Sets a default boolean in case a value is not provided for validation.### SS::integer()

[](#ssinteger)

methodparamsdescription`optional``?int $default`Sets a default integer in case a value is not provided for validation.`min``int $value`Checks if the value is above or equal to the one provided in parameter.`max``int $value`Checks if the value is below or equal to the one provided in parameter.`between``int $min`, `int $max`Checks if the value is between minimum and maximum provided in params.`equals``int $expected`Checks if the value is equal to the one provided in parameter.`not``int $unexpected`Checks if the value is not equal to the one provided in parameter.`oneOf``int[] $values`Checks if the value is one of the array provided in parameter.`notOneOf``int[] $values`Checks if the value is not one of the array provided in parameter.### SS::string()

[](#ssstring)

methodparamsdescription`optional``?string $default`Sets a default string in case a value is not provided for validation.`trim``bool $left = true`, `bool $right = true`Trims spaces from the start(in case $left = true) and from the end(in case $right = true). Note: at least one of both parameters have to be set to true.`length``bool $length`, `string $charset = 'UTF-8'`Checks if the value length is exactly the same as the one provided in $length parameter.`min``bool $length`, `string $charset = 'UTF-8'`Checks if the value length is greater or equal to the one provided in $length parameter.`max``bool $length`, `string $charset = 'UTF-8'`Checks if the value length is smaller or equal to the one provided in $length parameter.`oneOf``string[] $values`, `bool $strict = true`Checks if the value is one of the array provided in parameter.`notOneOf``string[] $values`, `bool $strict = true`Checks if the value is not one of the array provided in parameter.`email`-Checks if the value is a valid email address.`ip``bool $v4 = true`, `bool $v6 = false`Checks if the value is a valid IP address. Flags in parameters indicate if v4/v6 should be considered valid.`url``bool $httpsOnly = false`Checks if the value is a valid URL. $httpsOnly flags indicates in only https:// URLs should be considered valid.`regex``string $pattern`, `string $name = null`Checks if the value matches a specific regular expression pattern. Parameter $name is used for naming the pattern and will be displayed in error message instead of the whole pattern.`alpha``bool $dash = false`, `bool $space = false`Checks if the value contains only characters from A to Z, lower or uppercase. Parameter $dash indicates if `-` and `_` characters should also be allowed. Parameter `$space` indicates if spaces should also be allowed.`alphaNum``bool $dash = false`, `bool $space = false`Checks if the value contains only characters from A to Z, lower or uppercase + numbers. Parameter $dash indicates if `-` and `_` characters should also be allowed. Parameter `$space` indicates if spaces should also be allowed.### SS::date()

[](#ssdate)

methodparamsdescription`optional``?string $default`Sets a default date in case a value is not provided for validation. Value should be in the same format as instantiated date.`before``string $date`Checks if validated date is before the one provided in parameter.`after``string $date`Checks if validated date is after the one provided in parameter.### SS::arr()

[](#ssarr)

methodparamsdescription`optional``?array $default`Sets a default array in case a value is not provided for validation.`scalar`-Checks if all values of the validated array are scalar.`unique`-Checks if all values of the validated array are unique.`each``SanitizerSchema $schema`Checks if each of the values of the validated array satisfy the specified `$schema``schema``array $schema`Validates every key =&gt; value based on provided schema.`min``int $length`Validates if array has `$min` minimum length.`max``int $length`Validates if array has `$max` maximum length.### SS::decimal()

[](#ssdecimal)

methodparamsdescription`optional``?string/int/float $default`Sets a default string/int/float in case a value is not provided for validation.`min``string/int/float $value`Checks if the value is above or equal to the one provided in parameter.`max``string/int/float $value`Checks if the value is below or equal to the one provided in parameter.Custom error messages
=====================

[](#custom-error-messages)

Error messages are defined inside a static map `SanitizerException::$messages` and can be easily redefined. This can be used for multilingual messages for example.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

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

2302d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6d24f2697a611e30a86a4e7dff7578f5469c0dfedf7e7aa0a6db0b41d4f1211d?d=identicon)[dtimofeev](/maintainers/dtimofeev)

---

Top Contributors

[![dtimofeev](https://avatars.githubusercontent.com/u/20657756?v=4)](https://github.com/dtimofeev "dtimofeev (3 commits)")

---

Tags

libraryphpphp7sanitizationstandalone-libraryvalidation

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/dtimofeev-sanitizer/health.svg)

```
[![Health](https://phpackages.com/badges/dtimofeev-sanitizer/health.svg)](https://phpackages.com/packages/dtimofeev-sanitizer)
```

###  Alternatives

[webmozart/assert

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

7.6k894.0M1.2k](/packages/webmozart-assert)[bensampo/laravel-enum

Simple, extensible and powerful enumeration implementation for Laravel.

2.0k15.9M104](/packages/bensampo-laravel-enum)[nette/forms

📝 Nette Forms: generating, validating and processing secure forms in PHP. Handy API, fully customizable, server &amp; client side validation and mature design.

54013.2M448](/packages/nette-forms)[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)

PHPackages © 2026

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