PHPackages                             okipa/php-data-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. okipa/php-data-sanitizer

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

okipa/php-data-sanitizer
========================

Data sanitizer to auto-cast entries, convert empty strings to null, etc.

1.1.3(6y ago)59.5k↓66.7%21MITPHPPHP &gt;=7.2

Since May 4Pushed 6y ago1 watchersCompare

[ Source](https://github.com/Okipa/php-data-sanitizer)[ Packagist](https://packagist.org/packages/okipa/php-data-sanitizer)[ Docs](https://github.com/Okipa/php-data-sanitizer)[ RSS](/packages/okipa-php-data-sanitizer/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (6)Dependencies (4)Versions (7)Used By (1)

Data sanitizer to auto-cast entries, convert empty strings to null, etc.
========================================================================

[](#data-sanitizer-to-auto-cast-entries-convert-empty-strings-to-null-etc)

[![Source Code](https://camo.githubusercontent.com/8e43339a62a32787433e099fedc3157686425241cfcceedd8d75a7176565d9e9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f736f757263652d6f6b6970612f7068702d2d646174612d2d73616e6974697a65722d626c75652e737667)](https://github.com/Okipa/php-data-sanitizer)[![Latest Version](https://camo.githubusercontent.com/bce574ea2f83b01e3181c7895db092ef0696a56a1cb0784ba0068a89b165d93b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f6f6b6970612f7068702d646174612d73616e6974697a65722e7376673f7374796c653d666c61742d737175617265)](https://github.com/Okipa/php-data-sanitizer/releases)[![Total Downloads](https://camo.githubusercontent.com/0bfad3e04018b26f7255604d0067a8db4c4cecf59efe0eaea4e58f1bfd7c0d48/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6f6b6970612f7068702d646174612d73616e6974697a65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/okipa/php-data-sanitizer)[![License: MIT](https://camo.githubusercontent.com/08cef40a9105b6526ca22088bc514fbfdbc9aac1ddbf8d4e6c750e3a88a44dca/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d626c75652e737667)](https://opensource.org/licenses/MIT)[![Build Status](https://camo.githubusercontent.com/1b2009dc1d834539e3a7a121aab2e2032d5302231b33da6c7a6b3b493db10504/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4f6b6970612f7068702d646174612d73616e6974697a65722f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Okipa/php-data-sanitizer/build-status/master)[![Code Coverage](https://camo.githubusercontent.com/0142491fbfe3139fc818c3b6133e41c70275b77f219c73db5c8eb485af3a6faa/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4f6b6970612f7068702d646174612d73616e6974697a65722f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Okipa/php-data-sanitizer/?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/a6cddd8155b61a6a0794909457ab6073007a0a1a6621291f58e6cc4db4de554d/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4f6b6970612f7068702d646174612d73616e6974697a65722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Okipa/php-data-sanitizer/?branch=master)

Often when receiving data from a client in an API or from a form request, you'll find yourself running the same data cleaning operations such as transforming `'false'` to the boolean `false`, converting `''` to `null` etc. This can be a pain. This package simplifies the process drastically.

Compatibility
-------------

[](#compatibility)

Laravel version (optional)PHP versionPackage version^5.5^7.2^1.1^5.0^5.6^1.0Table of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
    - [Laravel users](#laravel-users)
    - [Without Laravel](#without-laravel)
- [Usage](#usage)
- [Testing](#testing)
- [Changelog](#changelog)
- [Contributing](#contributing)
- [Credits](#credits)
- [Licence](#license)

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

[](#installation)

- Install the package with composer :

```
composer require "okipa/php-data-sanitizer:^1.1"
```

### Laravel users

[](#laravel-users)

- Laravel 5.5+ uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider and the Facade alias. If you don't use auto-discovery or if you use a Laravel 5.4- version, add the package service provider in the `register()` method from your `app/Providers/AppServiceProvider.php` :

```
// php data sanitizer
// https://github.com/Okipa/php-data-sanitizer
$this->app->register(Okipa\DataSanitizer\Laravel\DataSanitizerServiceProvider::class);
```

- Then, add the package facade alias in the `$aliases` array from the `config/app.php`config file.

```
'aliases' => [
    '...',
    'DataSanitizer' => Okipa\DataSanitizer\Laravel\Facades\DataSanitizer::class
]
```

When this provider is booted, you'll gain access to a `DataSanitizer` facade, which you may use in your controllers.

```
public function index()
{
    $data = [
        // data to sanitize
    ];
    $sanitizedData = \DataSanitizer::sanitize($data);
}
```

### Without Laravel

[](#without-laravel)

DataSanitizer ships with native implementations of the bootloader and facade. In order to use it import class.

```
// import the package facade
use Acid\DataSanitizer\Native\Facades\DataSanitizer;

// sanitize your data
$data = ['false', '3', ''];
$sanitizedData = DataSanitizer::sanitize($data);

// produces [false, 3, null]
```

Usage
-----

[](#usage)

The only public method in the package is `sanitize($data, $default = null, $jsonDecodeAssoc = false)`. Call the sanitizer as following :

```
$data = ['null', 'true'];
$sanitizedData = DataSanitizer::sanitize($data);
```

`$data` can be a string, boolean, number, array, object or JSON string. Examples of the cleaned data :

```
''                  => null
' string trim '     => 'string trim'
'null'              => null
'false'             => false
'true'              => true
'on'                => true
'3'                 => 3
'5.07'              => 5.07
```

When using arrays and objects, the method will sanitize each element in the given data and return an array (or object) with the cleaned values. `$default` can be used to return a default value if the resulting cleaned data is `null` or `false`.

Example:

```
DataSanitizer::sanitize('', 'hello');
// will return 'hello'
```

`$jsonDecodeAssoc` is used for decoding JSON. See php [json\_decode documentation](http://php.net/manual/en/function.json-decode.php)

```
$jsonDecodeAssoc = true // default is false
$data = json_decode($data, null, $jsonDecodeAssoc);
// will decode your json as associative array (and as object if false)

```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Credits
-------

[](#credits)

- [Arthur LORENT](https://github.com/okipa)
- [Daniel Lucas](https://github.com/daniel-chris-lucas)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity62

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

Recently: every ~123 days

Total

6

Last Release

2435d ago

PHP version history (2 changes)1.0.0PHP ^5.6 | ^7.0

1.1.0PHP &gt;=7.2

### Community

Maintainers

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

---

Top Contributors

[![Okipa](https://avatars.githubusercontent.com/u/5328934?v=4)](https://github.com/Okipa "Okipa (1 commits)")

---

Tags

cleancodeigniterdatafuelphplaravelokipapackagephpsanitizesanitizerphplaravelpackagedatasanitizercodeigniterfuelphpcleansanitizeokipa

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/okipa-php-data-sanitizer/health.svg)

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

###  Alternatives

[okipa/laravel-table

Generate tables from Eloquent models.

56752.8k](/packages/okipa-laravel-table)[ondrej-vrto/php-filename-sanitize

Removes all forbidden characters from the file name or path.

1120.6k1](/packages/ondrej-vrto-php-filename-sanitize)[erlandmuchasaj/sanitize

A package to sanitize your input.

146.0k](/packages/erlandmuchasaj-sanitize)[okipa/laravel-form-components

Ready-to-use and customizable form components.

198.0k1](/packages/okipa-laravel-form-components)

PHPackages © 2026

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