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

ActiveYii2-extension[Validation &amp; Sanitization](/categories/validation)

raditzfarhan/yii2-sanitizer
===========================

Yii2 Sanitizer is an easy way to sanitize or filter your inputs.

1.0.1(6y ago)1271MITPHP

Since Jul 15Pushed 6y agoCompare

[ Source](https://github.com/raditzfarhan/yii2-sanitizer)[ Packagist](https://packagist.org/packages/raditzfarhan/yii2-sanitizer)[ RSS](/packages/raditzfarhan-yii2-sanitizer/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (1)Versions (4)Used By (0)

Yii2 Sanitizer
==============

[](#yii2-sanitizer)

Yii2 Sanitizer is an easy way to sanitize or filter your inputs for application that uses [Yii2 framework](https://www.yiiframework.com/).

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

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
composer require raditzfarhan/yii2-sanitizer "^1.0.0"

```

or add

```
"raditzfarhan/yii2-sanitizer": "^1.0.0"

```

to the require section of your `composer.json` file.

Release Changes
---------------

[](#release-changes)

> NOTE: Refer the [CHANGE LOG](https://github.com/raditzfarhan/yii2-sanitizer/blob/master/CHANGE.md) for details on changes to various releases.

Usage
-----

[](#usage)

Add this to the component section of your main config.

```
'components' => [
    ...
    'sanitizer' => [
        'class' => 'raditzfarhan\Yii2Sanitizer\Sanitize',
    ],
    ...
],
```

Examples
--------

[](#examples)

### Filters an array on inputs

[](#filters-an-array-on-inputs)

```
// data to be filtered
$data = [
    'name' => ' Farhan"',
    'address' => 'No 1, Residence ABC',
    'postcode' => '81221A',
    'points' => '-152.1711B',
    'status' => 'C1',
];

// create a filters corresponding to the input data array
$filters = [
    'name' => ['trim', 'escape'],
    'address' => ['trim', 'escape', 'cast:string'],
    'postcode' => ['digit'],
    'points' => ['digit'],
    'status' => ['cast:int'],
];

// call sanitize function to filter an array of inputs
$filtered_data = Yii::$app->sanitizer->sanitize($data, $filters);
var_dump($filtered_data);
```

Results in:

```
[
    'name' => 'Farhan\\\"'
    'address' => 'No 1, Residence ABC'
    'postcode' => 81221
    'points' => -152.1711
    'status' => '1'
]
```

Usage is fairly simple. Your filter array needs to match the data array with the filters as the array value. You can combine the filters and it will be executed in order from left to right.

### Filter single value

[](#filter-single-value)

```
// call filter function to filter a single value. You can add filter type as the second argument.
$filtered_data = Yii::$app->sanitizer->filter('No 1, Residence ABC', ['trim', 'cast:string']);
echo $filtered_data;
```

Results in:

```
No 1, Residence ABC
```

The first argument would be the value that needs filtering. The second argument would be the filters that needs to be applied.

Available Filters
-----------------

[](#available-filters)

Here are the filters that you can use:

FilterDescription**cast**Cast given value into given type. Options are int, float, string.**digit**Will removes non-digit from given value.**encode**Escaping unwanted tags and only output plain HTML using Yii2 HTML:encode() function.**escape**Quote string with slashes using filter\_var (FILTER\_SANITIZE\_MAGIC\_QUOTES) function.**float**Removes unwanted characters and remain a float number only. Similar to cast:float.**int**Removes unwanted characters and remain a integer number only. Similar to case:int.**purify**Purify HTML content using Yii2 HtmlPurifier::process() function. Note that HtmlPurifier processing is quite heavy so use with caution.**strip\_tags**Removes HTML tags from given string value.**trim**Trims a string and remove white spaces.License
-------

[](#license)

**Yii2 Sanitizer** is released under the [MIT license](http://opensource.org/licenses/MIT)

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 55.6% 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 ~0 days

Total

2

Last Release

2494d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1203676?v=4)[Raditz Farhan](/maintainers/raditzfarhan)[@raditzfarhan](https://github.com/raditzfarhan)

---

Top Contributors

[![farhan928](https://avatars.githubusercontent.com/u/8623033?v=4)](https://github.com/farhan928 "farhan928 (5 commits)")[![raditzfarhan](https://avatars.githubusercontent.com/u/1203676?v=4)](https://github.com/raditzfarhan "raditzfarhan (4 commits)")

### Embed Badge

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

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

###  Alternatives

[borales/yii2-phone-input

Yii2 International telephone numbers - Asset Bundle, Behavior, Validator, Widget

1341.6M6](/packages/borales-yii2-phone-input)[codeonyii/yii2-at-least-validator

Validates at least one (or more) attributes.

28253.5k1](/packages/codeonyii-yii2-at-least-validator)[arogachev/yii2-many-to-many

Many-to-many ActiveRecord relation for Yii 2 framework

3541.2k4](/packages/arogachev-yii2-many-to-many)[yiibr/yii2-br-validator

Provide validations and features for brazilian localization

14103.2k4](/packages/yiibr-yii2-br-validator)[yii2mod/yii2-validators

Collection of useful validators for Yii Framework 2.0

1816.8k](/packages/yii2mod-yii2-validators)

PHPackages © 2026

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