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

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

vypsen/sanitizer
================

sanitizer lib for php

01PHP

Since Jan 15Pushed 3y ago1 watchersCompare

[ Source](https://github.com/Vypsen/Sanitizer)[ Packagist](https://packagist.org/packages/vypsen/sanitizer)[ RSS](/packages/vypsen-sanitizer/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Sanitizer
=========

[](#sanitizer)

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

[](#installation)

```
composer require vypsen/sanitizer dev-master

```

Filters
-------

[](#filters)

filterdescription\['array' '`type`'\]array of the same type of elements (`type`: \['string', 'int', 'float', 'bool'\])'float'converts in float type'int'converts in integer type'ru\_number\_phone'checks and normalizes the Russian phone number'string'converts in string type'structure'converts a json object into an associative arrayExample
-------

[](#example)

```
use Vypsen\Sanitizer\Sanitizer;

$jsonData = '{"arr": ["1", 2, "3"], "foo": "123", "bar": 123, "baz": "8 (950) 288-56-23", "qwe": {"123": "qwerty", "abc": 321}}';

$filters = [
    "arr" => ['array', 'int'],
    "foo" => 'int',
    "bar" => 'string',
    "baz" => 'ru_number_phone',
    "qwe" => 'structure'
];

$data = Sanitizer::applySanitizers($jsonData, $filters);
var_dump($data);
```

Result
------

[](#result)

```
[
    'arr' => [1, 2, 3],
    'foo' => 123,
    'bar' => '123',
    'baz' => '79502885623',
    'qwe' => ['123' => 'qwerty', 'abc' => 321],
];
```

Tests
-----

[](#tests)

### To run tests

[](#to-run-tests)

```
./vendor/bin/phpunit ./vendor/vypsen/sanitizer/tests

```

Custom filter
-------------

[](#custom-filter)

For a custom filter, you need to create a class that will implements Vypsen\\Sanitizer\\Interfaces\\Filter

### example

[](#example-1)

```
use Vypsen\Sanitizer\Interfaces\Filter;

class TestClass implements Filter
{
    public function sanitize($value, $option): string
    {
        return ucfirst($value);
    }

    public function validation($value): bool
    {
        return is_string($value);
    }

    public function errorMessageValid(): string
    {
        return 'value must be a string';
    }
}
```

to apply a filter

```
require_once('TestClass.php');

$jsonData = '{"arr": ["1", 2, "3"], "foo": "abs"}';

$filters = [
    "arr" => ['array', 'string'],
    "foo" => TestClass::class,
];

$data = Sanitizer::applySanitizers($jsonData, $filters);
var_dump($data);
```

result

```
[
    'arr' => ['1', '2', '3'],
    'foo' => 'Abs'
];
```

###  Health Score

13

—

LowBetter than 1% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity1

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity23

Early-stage or recently created project

 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.

### Community

Maintainers

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

---

Top Contributors

[![Vypsen](https://avatars.githubusercontent.com/u/61196603?v=4)](https://github.com/Vypsen "Vypsen (14 commits)")

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/vypsen-sanitizer/health.svg)](https://phpackages.com/packages/vypsen-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.9M105](/packages/bensampo-laravel-enum)[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)

PHPackages © 2026

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