PHPackages                             grip/trimfilter - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. grip/trimfilter

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

grip/trimfilter
===============

HTML whitespace filter for PHP

1.0.0(2y ago)01.1kApache-2.0PHP

Since Mar 8Pushed 2y ago1 watchersCompare

[ Source](https://github.com/GripOnline/php-trimfilter)[ Packagist](https://packagist.org/packages/grip/trimfilter)[ RSS](/packages/grip-trimfilter/feed)WikiDiscussions main Synced 1mo ago

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

HTML whitespace filter for PHP
==============================

[](#html-whitespace-filter-for-php)

This library provides an HTML whitespace filter that you can use to filter out unneeded whitespace from generated HTML. It does not buffer the whole page so it will not hurt your time-to-first-byte (TTFB). Some buffering is required, but you can set the buffer size yourself. A buffer of around 500 bytes is recommended. Contents of `` / `` / `` / `` and comment tags are never trimmed.

Example
=======

[](#example)

This filter turns this

```
>

	Online koploper worden | Grip Online

```

into this:

```
>

Online koploper worden | Grip Online

```

Installing
==========

[](#installing)

The library can be installed using Composer:

```
$ composer require grip/trimfilter
```

Usage
=====

[](#usage)

Example usage with Twig template rendering:

```
$trimFilter = new Grip\HtmlWhitespaceFilter();

ob_start(array($trimFilter, 'filter'), 500);

$template = $twig->load('index.html');
$template->display(['the' => 'variables', 'go' => 'here']);

ob_end_flush();

$trimFilter->endFlush();
```

Caveats
=======

[](#caveats)

This library only works with with single-byte character encodings and UTF-8.

Background
==========

[](#background)

We like our HTML as clean as possible. When working with a template engine (such as Twig), indenting template tags can introduce a whole lot of whitespace in the output. That's why we created this filter in the first place. Other than that, most whitespace in HTML can be seen as 'waste'. It may be true that the excessive whitespace compresses quite well using gzip or brotli, but on the client side it will be sent uncompressed to the HTML parser.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 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

Unknown

Total

1

Last Release

802d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0ed6c799c1eca69098542557b458f3baa1335b97da20b8794d3cca7eddc558da?d=identicon)[CodeBosw8r](/maintainers/CodeBosw8r)

---

Top Contributors

[![CodeBosw8r](https://avatars.githubusercontent.com/u/8860699?v=4)](https://github.com/CodeBosw8r "CodeBosw8r (11 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/grip-trimfilter/health.svg)

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

PHPackages © 2026

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