PHPackages                             acid-solutions/input-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. [API Development](/categories/api)
4. /
5. acid-solutions/input-sanitizer

AbandonedArchivedLibrary[API Development](/categories/api)

acid-solutions/input-sanitizer
==============================

Input sanitizer to convert strings to booleans, numbers etc.

1.0.2(8y ago)22.6kMITPHPPHP ^5.6 | ^7.0

Since Oct 16Pushed 8y ago3 watchersCompare

[ Source](https://github.com/ACID-Solutions/input-sanitizer)[ Packagist](https://packagist.org/packages/acid-solutions/input-sanitizer)[ Docs](https://github.com/ACID-Solutions/input-sanitizer)[ RSS](/packages/acid-solutions-input-sanitizer/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (2)Dependencies (3)Versions (4)Used By (0)

Input Sanitizer
===============

[](#input-sanitizer)

[![Source Code](https://camo.githubusercontent.com/9ff5a605bce147e826a08d08d077562fb815eef00d9fdbc5fc1a4f44c4dbea50/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f736f757263652d414349442d2d536f6c7574696f6e73253246696e7075742d2d73616e6974697a65722d626c75652e737667)](https://github.com/ACID-Solutions/input-sanitizer)[![Latest Version](https://camo.githubusercontent.com/a6199ddde1e8c722e0a7151d751fb825a9c914a8a1c575ea0df19f9356bde78b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f414349442d536f6c7574696f6e732f696e7075742d73616e6974697a65722e7376673f7374796c653d666c61742d737175617265)](https://github.com/ACID-Solutions/input-sanitizer/releases)[![Build Status](https://camo.githubusercontent.com/26a45c05f005409d70758348b57f70a1549daa2088ef87276375aa221b021656/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f414349442d536f6c7574696f6e732f696e7075742d73616e6974697a65722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/ACID-Solutions/input-sanitizer)[![Coverage Status](https://camo.githubusercontent.com/2db9af8346cdfa431a0e093facc9a934df86f908fca012f577993d071a4a3465/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f414349442d536f6c7574696f6e732f696e7075742d73616e6974697a65722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/ACID-Solutions/input-sanitizer/code-structure)[![Total Downloads](https://camo.githubusercontent.com/89caea2809a09e2ed003785ad141aedeaf74e962ca313b4281ed9b2f3d3d3d48/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f414349442d536f6c7574696f6e732f696e7075742d73616e6974697a65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ACID-Solutions/input-sanitizer)[![License: MIT](https://camo.githubusercontent.com/08cef40a9105b6526ca22088bc514fbfdbc9aac1ddbf8d4e6c750e3a88a44dca/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d626c75652e737667)](https://opensource.org/licenses/MIT)[![SensioLabsInsight](https://camo.githubusercontent.com/9fae86ead8c6250e0cc378b4784971fdffce148fd71466ac988f7a0183c34d72/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f33633537373735342d393130312d343437332d616262322d3530313535656436373238322f736d616c6c2e706e67)](https://insight.sensiolabs.com/projects/3c577754-9101-4473-abb2-50155ed67282)

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.

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

[](#installation)

- Install the package with composer :

```
composer require acid-solutions/input-sanitizer
```

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` :

```
// input sanitizer
// https://github.com/ACID-Solutions/input-sanitizer
$this->app->register(AcidSolutions\InputSanitizer\Laravel\InputSanitizerServiceProvider::class);
```

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

```
'aliases' => [
    '...',
    'InputSanitizer' => AcidSolutions\InputSanitizer\Laravel\Facades\InputSanitizer::class
]
```

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

```
public function index()
{
    $inputs = $request->all();
    $sanitizedInputs = \InputSanitizer::sanitize($inputs);
}
```

Without Laravel
---------------

[](#without-laravel)

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

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

// sanitize your entries
$input = ['false', '3', ''];
$sanitizedInput = InputSanitizer::sanitize($input);

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

Usage
-----

[](#usage)

The only public method in the package is `sanitize($input, $default = null, $jsonDecodeAssoc = false)`

Call the sanitizer as following:

```
$data = ['null', 'true'];
$sanitized = InputSanitizer::sanitize($data);
```

`$input` can be a string, boolean, number, array, object or JSON string

Examples of the cleaned data:

```
''      => null
'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 input and return an array (or object) with the cleaned values.

`$default` can be used to return a default value if the resulting cleaned input is `null` or `false`

Example:

```
InputSanitizer::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
$input = json_decode($input, null, $jsonDecodeAssoc);
// will decode your json as associative array (and as object if false)

```

Credits
-------

[](#credits)

- [Arthur Lorent](https://github.com/Okipa)
- [Daniel Lucas](https://github.com/daniel-chris-lucas)

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 51.4% 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 ~195 days

Total

3

Last Release

3105d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e0872a7b81ab21033b2fe8ffcca970ca17a28b92ba9638ae90621ed826d7acb7?d=identicon)[daniel-acid](/maintainers/daniel-acid)

---

Top Contributors

[![dan-lucas](https://avatars.githubusercontent.com/u/6905981?v=4)](https://github.com/dan-lucas "dan-lucas (19 commits)")[![daniel-chris-lucas](https://avatars.githubusercontent.com/u/2169418?v=4)](https://github.com/daniel-chris-lucas "daniel-chris-lucas (12 commits)")[![Okipa](https://avatars.githubusercontent.com/u/5328934?v=4)](https://github.com/Okipa "Okipa (6 commits)")

---

Tags

apidata-cleaningfacadelaravelsanitizerphplaravelpackagesanitizercodeigniterfuelphpcleaninputsanitizeacid

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/acid-solutions-input-sanitizer/health.svg)

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

###  Alternatives

[joisarjignesh/bigbluebutton

BigBlueButton Server API Library for Laravel

162145.5k1](/packages/joisarjignesh-bigbluebutton)[resend/resend-laravel

Resend for Laravel

1191.4M6](/packages/resend-resend-laravel)[joggapp/laravel-aws-sns

Laravel package for the SNS events by AWS

3171.8k](/packages/joggapp-laravel-aws-sns)[dariusiii/tmdb-laravel

Laravel Package for TMDB ( The Movie Database ) API. Provides easy access to the wtfzdotnet/php-tmdb-api library.

1821.1k](/packages/dariusiii-tmdb-laravel)

PHPackages © 2026

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