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

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

popphp/pop-filter
=================

Pop Filter Component for Pop PHP Framework

4.0.4(6mo ago)424.0k—7.7%4BSD-3-ClausePHPPHP &gt;=8.3.0CI passing

Since Jul 22Pushed 6mo ago1 watchersCompare

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

READMEChangelog (10)Dependencies (2)Versions (21)Used By (4)

pop-filter
==========

[](#pop-filter)

[![Build Status](https://github.com/popphp/pop-filter/workflows/phpunit/badge.svg)](https://github.com/popphp/pop-filter/actions)[![Coverage Status](https://camo.githubusercontent.com/9a15ff738ad92173116bd1885619e1e97fff729a7743ff2110cdd53b889df485/687474703a2f2f63632e706f707068702e6f72672f636f7665726167652e7068703f636f6d703d706f702d66696c746572)](http://cc.popphp.org/pop-filter/)

[![Join the chat at https://discord.gg/TZjgT74U7E](https://camo.githubusercontent.com/acad7b0eeb78b78d08ffd2b85681ab243436388b5f86f8bcb956a69246e53739/68747470733a2f2f6d656469612e706f707068702e6f72672f696d672f646973636f72642e737667)](https://discord.gg/TZjgT74U7E)

- [Overview](#overview)
- [Install](#install)
- [Quickstart](#quickstart)
- [Extending](#extending)
- [Excludes](#excludes)

Overview
--------

[](#overview)

`pop-filter` is a component for applying filtering callbacks to values that need to be consumed by other areas of an application. It can be used for input security as well general input scrubbing as well.

`pop-filter` is a component of the [Pop PHP Framework](https://www.popphp.org/).

[Top](#pop-filter)

Install
-------

[](#install)

Install `pop-filter` using Composer.

```
composer require popphp/pop-filter

```

Or, require it in your composer.json file

```
"require": {
    "popphp/pop-filter" : "^4.0.4"
}

```

[Top](#pop-filter)

Quickstart
----------

[](#quickstart)

### Simple Filter

[](#simple-filter)

If you want to create a simple, single filter and use it to filter some values, you can do this:

```
$filter = new Pop\Filter\Filter('strip_tags');
$values = [
    'username' => 'admin',
    'email'    => 'test@test.com'
];
$values = $filter->filter($values);
```

The values above have been filtered and had the tags stripped:

```
$values = [
    'username' => 'admin',
    'email'    => 'test@test.com'
];

```

[Top](#pop-filter)

Extending
---------

[](#extending)

### The Filterable Trait

[](#the-filterable-trait)

The component comes with a trait called `Pop\Filter\FilterableTrait`. If you wish to have the filter component and its features included in your application, you can create a class that uses this trait. With it, your class will be able to add filters and call the methods to filter the necessary values. These filters can either be an instance of `Pop\Filter\FilterInterface` (e.g., `Pop\Filter\Filter`) or a basic callable.

```
namespace MyApp\Model

use Pop\Filter\FilterableTrait;

class User
{

    use FilterableTrait;

    /**
     * Filter values
     *
     * @param  array $values
     * @return array
     */
    public function filter(array $values)
    {
        foreach ($this->filters as $filter) {
            foreach ($values as $key => $value) {
                $values[$key] = $filter->filter($value, $key);
            }
        }

        return $values;
    }

}
```

With the above code, you can create a user model, add filters to it and filter values with it:

```
$user = new User();
$user->addFilters([
    'strip_tags',
    new Pop\Filter\Filter('htmlentities', [ENT_QUOTES, 'UTF-8']),
]);

$values = [
    'username'   => '"Admin"',
    'first_name' => 'John\'s',
    'last_name'  => 'Doe'
];

$values = $user->filter($values);
```

The values are now filtered and look like:

```
$values = [
    'username'   => '&quot;Admin&quot;',
    'first_name' => 'John&#039;s',
    'last_name'  => 'Doe'
];

```

The tags have been stripped and the entities have been converted to HTML. Notice the first filter added was the callable `strip_tags` and the second filter added was an instance of `Pop\Filter\Filter` with parameters.

[Top](#pop-filter)

Excludes
--------

[](#excludes)

### Fine-Grained Control

[](#fine-grained-control)

Two properties are available to the `filter` method within the `Pop\Filter\AbstractFilter` class. They are `excludeByName` and `excludeByType`. With them, you can have fine-tuned control over what values actually get filtered. For example, if you don't want to filter any values named `username`, you can do this:

```
$filter = new Pop\Filter\Filter('strip_tags', null, 'username');
$values = [
    'username' => 'admin',
    'email'    => 'test@test.com'
];

foreach ($values as $key => $value) {
    $values[$key] = $filter->filter($value, $key);
}
```

Because of the third parameter in the above constructor, the `username` is excluded from being filtered and the values look like this:

```
$values = [
    'username' => 'admin',
    'email'    => 'test@test.com'
];

```

The fourth parameter of the filter constructor is `$excludeByType` and that is useful for excluding a number of values at once that are all of the same type, for example, textareas within a form object.

[Top](#pop-filter)

###  Health Score

54

—

FairBetter than 97% of packages

Maintenance66

Regular maintenance activity

Popularity31

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity87

Battle-tested with a long release history

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

Recently: every ~180 days

Total

16

Last Release

201d ago

Major Versions

2.1.0p1 → 3.0.02019-11-19

3.2.1 → 4.0.02023-11-09

PHP version history (7 changes)2.0.0PHP &gt;=5.4.0

3.0.0PHP &gt;=7.1.0

3.2.0PHP &gt;=7.3.0

3.2.1PHP &gt;=7.4.0

4.0.0PHP &gt;=8.1.0

4.0.2PHP &gt;=8.2.0

4.0.4PHP &gt;=8.3.0

### Community

Maintainers

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

---

Top Contributors

[![nicksagona](https://avatars.githubusercontent.com/u/898670?v=4)](https://github.com/nicksagona "nicksagona (49 commits)")

---

Tags

phpstringfilterpoppop phpstring filter

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[vria/nodiacritic

Tiny helper function that removes all diacritical signs from characters

113.1M13](/packages/vria-nodiacritic)[popphp/pop-db

Pop Db Component for Pop PHP Framework

1814.6k11](/packages/popphp-pop-db)[popphp/pop-pdf

PHP PDF library for generating and importing PDF documents. A component of the Pop PHP Framework

207.8k1](/packages/popphp-pop-pdf)[popphp/pop-http

Pop Http Component for Pop PHP Framework

1018.5k13](/packages/popphp-pop-http)

PHPackages © 2026

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