PHPackages                             caridea/filter - 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. caridea/filter

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

caridea/filter
==============

A shrimp of a value sanitation library

3.0.0(8y ago)0361Apache-2.0PHPPHP &gt;=7.1.0

Since Sep 16Pushed 8y ago2 watchersCompare

[ Source](https://github.com/libreworks/caridea-filter)[ Packagist](https://packagist.org/packages/caridea/filter)[ Docs](http://github.com/libreworks/caridea-filter)[ RSS](/packages/caridea-filter/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (1)Versions (5)Used By (0)

caridea-filter
==============

[](#caridea-filter)

Caridea is a miniscule PHP application library. This shrimpy fellow is what you'd use when you just want some helping hands and not a full-blown framework.

[![](https://camo.githubusercontent.com/3a9d2bd9abd336c1541d254cd07f8dff935288ad4a0983294f0b3f572f5b0f4b/687474703a2f2f6c69627265776f726b732e636f6d2f636172696465612d3130302e706e67)](https://camo.githubusercontent.com/3a9d2bd9abd336c1541d254cd07f8dff935288ad4a0983294f0b3f572f5b0f4b/687474703a2f2f6c69627265776f726b732e636f6d2f636172696465612d3130302e706e67)

This is its value sanitation library.

[![Packagist](https://camo.githubusercontent.com/e8ae2150737a1c392ac818e79ae3903fce052b96be4a6faf2a0e9bea15d4efb6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636172696465612f66696c7465722e737667)](https://packagist.org/packages/caridea/filter)[![Build Status](https://camo.githubusercontent.com/acc79074edb0e988bdd7826020c2f64c59ee8d50ede1d269b4517f5cbf6af8ce/68747470733a2f2f7472617669732d63692e6f72672f6c69627265776f726b732f636172696465612d66696c7465722e737667)](https://travis-ci.org/libreworks/caridea-filter)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/d355fe9844d7f6f21f58d9bdd88e12c72c131ba3c6595ef2ad8e51aa50973b1f/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6c69627265776f726b732f636172696465612d66696c7465722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/libreworks/caridea-filter/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/22e660c9ad1650cc140ad00967e2d4f279a0d76b68988c144ea7e450467d5d44/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6c69627265776f726b732f636172696465612d66696c7465722f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/libreworks/caridea-filter/?branch=master)[![Documentation Status](https://camo.githubusercontent.com/2b7c54cba8eed82afca51c4deac50ab41756d5a555cd1bcf021d2267d6861b36/687474703a2f2f72656164746865646f63732e6f72672f70726f6a656374732f636172696465612d66696c7465722f62616467652f3f76657273696f6e3d6c6174657374)](http://caridea-filter.readthedocs.io/en/latest/?badge=latest)

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

[](#installation)

You can install this library using Composer:

```
$ composer require caridea/filter
```

- The master branch (version 3.x) of this project requires PHP 7.1 and the `mbstring` extension.
- Version 2.x of this project requires PHP 7.0 and the `mbstring` extension.

Compliance
----------

[](#compliance)

Releases of this library will conform to [Semantic Versioning](http://semver.org).

Our code is intended to comply with [PSR-1](http://www.php-fig.org/psr/psr-1/), [PSR-2](http://www.php-fig.org/psr/psr-2/), and [PSR-4](http://www.php-fig.org/psr/psr-4/). If you find any issues related to standards compliance, please send a pull request!

Documentation
-------------

[](#documentation)

- Head over to [Read the Docs](http://caridea-filter.readthedocs.io/en/latest/)

Examples
--------

[](#examples)

Just a few quick examples. Let's define a set of filters for a person record.

```
// let's pretend this came from $_POST
$input = [
    'name' => 'john smith  ',
    'birthday' => '1990-01-01__',
    'bio' => "Mistakenly written on Windows\r\nThat's a problem.  ",
    'friends' => 'Jane'
];

$registry = new \Caridea\Filter\Registry(); // you can register your own filters if you choose
$b = $registry->builder();
$b->always('name')->then('trim')->then('titlecase'); // always() will run chain even if missing from input
$b->field('birthday')->then('regex', '/[^0-9-]/', '');
$b->field('bio')->then('trim')->then('nl'); // convert to UNIX newlines
$b->always('species')->then('default', 'Homo sapiens');
$b->field('friends')->then('array')->each('trim'); // each() will run the filter on every element
// by default, all fields you don't specify are dropped.
// but! otherwise() can specify a fallback chain for any non-declared fields.
// $b->otherwise('trim')->then('default', null);
$filter = $b->build();
$output = $filter($input);
var_dump($output);
```

```
array(5) {
  'name' =>
  string(10) "John Smith"
  'birthday' =>
  string(10) "1990-01-01"
  'bio' =>
  string(47) "Mistakenly written on Windows
That's a problem."
  'species' =>
  string(12) "Homo sapiens"
  'friends' =>
  array(1) {
    [0] =>
    string(4) "Jane"
  }
}

```

You can also supply one or more `Reducer`s which are intended to combine and rewrite multiple values at once.

```
// let's pretend this came from $_POST
$input = [
    'username' => '  doublecompile  ',
    'id-0' => '1',
    'id-5' => '4',
    'id-1' => '9'
];

$registry = new \Caridea\Filter\Registry();
$b = $registry->builder();
$b->always('username')->then('trim');
$b->reducer(Combiners::appender('ids', 'id-'));
$filter = $b->build();
$output = $filter($input);
var_dump($output);
```

```
array(2) {
  'username' =>
  string(13) "doublecompile"
  'ids' =>
  array(3) {
    [0] =>
    string(1) "1"
    [1] =>
    string(1) "4"
    [2] =>
    string(1) "9"
  }
}

```

The `Filter` class itself is a `Reducer`.

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity61

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

Total

4

Last Release

3083d ago

Major Versions

2.0.x-dev → 3.0.02018-01-20

PHP version history (2 changes)2.0.0PHP &gt;=7.0.0

3.0.0PHP &gt;=7.1.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/659262eac941ffe4795493834425fc9a2369c2c9df3cc565ed4194f1d37be934?d=identicon)[doublecompile](/maintainers/doublecompile)

---

Top Contributors

[![doublecompile](https://avatars.githubusercontent.com/u/4267230?v=4)](https://github.com/doublecompile "doublecompile (10 commits)")

---

Tags

filtersanitizesanitation

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/caridea-filter/health.svg)

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

###  Alternatives

[clue/stream-filter

A simple and modern approach to stream filtering in PHP

1.7k271.5M8](/packages/clue-stream-filter)[aura/filter

Filters to validate and sanitize objects and arrays.

157571.0k12](/packages/aura-filter)[laminas/laminas-filter

Programmatically filter and normalize data and files

9529.5M173](/packages/laminas-laminas-filter)[htmlawed/htmlawed

Official htmLawed PHP library for HTML filtering

411.2M12](/packages/htmlawed-htmlawed)[kalfheim/sanitizer

Data sanitizer for PHP with built-in Laravel support.

1423.8k](/packages/kalfheim-sanitizer)[phpsanitization/phpsanitization

Modern PHP Sanitization Library

181.5k](/packages/phpsanitization-phpsanitization)

PHPackages © 2026

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