PHPackages                             ircmaxell/filterus - 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. [Search &amp; Filtering](/categories/search)
4. /
5. ircmaxell/filterus

ActiveLibrary[Search &amp; Filtering](/categories/search)

ircmaxell/filterus
==================

A library for filtering variables in PHP

1.0.0(9y ago)44813.4k52[3 PRs](https://github.com/ircmaxell/filterus/pulls)3MITPHPPHP &gt;=5.3.0

Since Feb 20Pushed 7y ago25 watchersCompare

[ Source](https://github.com/ircmaxell/filterus)[ Packagist](https://packagist.org/packages/ircmaxell/filterus)[ Docs](https://github.com/ircmaxell/filterus)[ RSS](/packages/ircmaxell-filterus/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (3)Used By (3)

Filterus - A flexible PHP 5.3 filter package
============================================

[](#filterus---a-flexible-php-53-filter-package)

Filter Methods:
---------------

[](#filter-methods)

Each filter class has two primary methods:

- `$filter->filter($var)` - returns a modified version of `$var` filtered to the options. If it cannot be safely modified, a default value will be returned.
- `$filter->validate($var)` - Returns a boolean identifying if the value is valid.

Simple Filters (with options):
------------------------------

[](#simple-filters-with-options)

- `alnum` - Alpha numeric
    - `min` - 0 - Minimum length
    - `max` - PHP\_INT\_MAX - Maximum length
    - `default` - `''` - Default return value
- `array` - Array matching
    - `min` - 0 - Minimum size
    - `maximum` - PHP\_INT\_MAX - Maximum size
    - `keys` - `null` - Filter to run on the keys
    - `values` - `null` - Filter to run on the values
    - `default` - `array()` - Default return value
- `bool` - Boolean matching
    - `default` - `null` - Default return value
- `email` - Matches emails
- `float` - Floating point numbers
    - `min` - `null` - Minimum length
    - `max` - `null` - Maximum length
    - `default` - 0.0 - Default return value
- `int` - Integers numbers
    - `min` - `null` - Minimum length
    - `max` - `null` - Maximum length
    - `default` - 0 - Default return value
- `ip` - Matches IP addresses
    - `ipv4` - `true` - Boolean to match IPv4 addresses
    - `ipv6` - `true` - Boolean to match IPv6 addresses
    - `private` - `true` - Include private addresses?
    - `reserved` - `true` - Include reserved addresses?
- `object` - Objects
    - `class` - `''` - Required class or interface name
    - `default` - `null` - The default value
    - `defaultFactory` - `null` - A callback to instantiate a return value
- `raw` - Returns whatever is passed in
- `regex` - Matches strings via a regex
    - `min` - 0 - Minimum length
    - `max` - PHP\_INT\_MAX - Maximum length
    - `default` - `''` - Default return value
    - `regex` - `/.?/` - The regex to run
- `string` - Matches strings
    - `min` - 0 - Minimum length
    - `max` - PHP\_INT\_MAX - Maximum length
    - `default` - `''` - Default return value
- `url` - Matches URLs
    - `path` - `false` - Force a path to be present
    - `query` - `false` - Force a query string to be present

Complex Filters
---------------

[](#complex-filters)

- `Filter::map(array())` - "maps" several filters over key-value pairs. Useful for filtering associative arrays or stdclass objects.
- `Filter::chain($filter1, $filter2...)` - Chains multiple filters together to run on the same value (similar to `AND` joining filters).
- `Filter::pool($filter1, $filter2...)` - Runs the same value through multiple filters using the first valid return (similar to `OR` joining filters)

Usage:
------

[](#usage)

Simple filters can be specified using a comma-separated-value list. So a filter specifying a string with minimum length of 5 could be represented as:

```
$filter = Filter::factory('string,min:5');
```

Or

```
$filter = new Filters\String(array('min' => 5));
```

If you pass a filter to `Filter::factory()`, it will be returned unmodified. So you can write functions like:

```
function foo($bar, $filter) {
    // do something with $bar and set in $baz
    return Filter::factory($filter)->filter($baz);
}
```

Complex chaining can also be supported. So if you wanted to check if an array with a minimum size of 4, with numeric keys and containing strings of minimum length 5, that could be built like so:

```
$filter = Filter::array('min:4', 'int', 'string,min:5');
```

If we wanted to validate an associative array, we would use a "map" filter:

```
$array = array(
    'foo' => 2,
    'bar' => 'test',
);

$filter = Filter::map(array(
    'foo' => 'int',
    'bar' => 'string,min:4',
));

var_dump($filter->validate($array)); // true
```

Procedural Interface
--------------------

[](#procedural-interface)

Filterus also ships with a procedural interface for calling filters.

```
\Filterus\filter($var, $filter);
```

And

```
\Filterus\validate($var, $filter);
```

Any filter is supported (both are basically simple wrappers):

```
function \Filterus\filter($var, $filter) {
    return \Filterus\Filter::factory($filter)->filter($var);
}
```

Both are just convenience functions.

Security Vulnerabilities
========================

[](#security-vulnerabilities)

If you have found a security issue, please contact the author directly at .

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity44

Moderate usage in the ecosystem

Community29

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 81.3% 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 ~541 days

Total

2

Last Release

3560d ago

### Community

Maintainers

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

---

Top Contributors

[![ircmaxell](https://avatars.githubusercontent.com/u/660654?v=4)](https://github.com/ircmaxell "ircmaxell (13 commits)")[![bocharsky-bw](https://avatars.githubusercontent.com/u/3317635?v=4)](https://github.com/bocharsky-bw "bocharsky-bw (1 commits)")[![frostbane](https://avatars.githubusercontent.com/u/12523422?v=4)](https://github.com/frostbane "frostbane (1 commits)")[![hostyle](https://avatars.githubusercontent.com/u/979761?v=4)](https://github.com/hostyle "hostyle (1 commits)")

---

Tags

securityfilter

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ircmaxell-filterus/health.svg)

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

###  Alternatives

[clue/stream-filter

A simple and modern approach to stream filtering in PHP

1.7k261.7M7](/packages/clue-stream-filter)[laminas/laminas-filter

Programmatically filter and normalize data and files

9428.0M150](/packages/laminas-laminas-filter)[friendsofcake/search

CakePHP Search plugin using PRG pattern

1742.0M37](/packages/friendsofcake-search)[soosyze/kses

An HTML/XHTML filter written in PHP. Checks on attribute values. Can be used to avoid Cross-Site Scripting (XSS), Buffer Overflows and Denial of Service attacks, among other things.

1258.5k1](/packages/soosyze-kses)[outl1ne/nova-input-filter

An input filter for Laravel Nova

24822.7k](/packages/outl1ne-nova-input-filter)[vria/nodiacritic

Tiny helper function that removes all diacritical signs from characters

113.1M13](/packages/vria-nodiacritic)

PHPackages © 2026

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