PHPackages                             sensiolabs/ansi-to-html - 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. sensiolabs/ansi-to-html

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

sensiolabs/ansi-to-html
=======================

A library to convert a text with ANSI codes to HTML

v2.0.0(1y ago)2537.8M—6.6%37[9 issues](https://github.com/sensiolabs/ansi-to-html/issues)[3 PRs](https://github.com/sensiolabs/ansi-to-html/pulls)20MITPHPPHP &gt;=8.0CI passing

Since Mar 19Pushed 1y ago12 watchersCompare

[ Source](https://github.com/sensiolabs/ansi-to-html)[ Packagist](https://packagist.org/packages/sensiolabs/ansi-to-html)[ RSS](/packages/sensiolabs-ansi-to-html/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (14)Used By (20)

ANSI to HTML5 Converter
=======================

[](#ansi-to-html5-converter)

This small library only does one thing: converting a text containing ANSI codes to an HTML5 fragment:

```
require_once __DIR__.'/vendor/autoload.php';

use SensioLabs\AnsiConverter\AnsiToHtmlConverter;

$converter = new AnsiToHtmlConverter();

$html = $converter->convert($ansi);
```

The `$ansi` variable should contain a text with ANSI codes, and `$html` will contain the converted HTML5 version of it.

You can then output the HTML5 fragment in any HTML document:

```

        10px 15px; font-family: monospace;"
        >

```

The converter supports different color themes:

```
use SensioLabs\AnsiConverter\Theme\SolarizedTheme;

$theme = new SolarizedTheme();
$converter = new AnsiToHtmlConverter($theme);
```

By default, the colors are inlined into the HTML, but you can also use classes by turning off style inlining:

```
$converter = new AnsiToHtmlConverter($theme, false);
```

And the `asCss()` method of the theme object lets you retrieve the theme styles as a CSS snippet:

```
$styles = $theme->asCss();
```

which you can then use in your HTML document:

```

            .ansi_box { overflow: auto; padding: 10px 15px; font-family: monospace; }

```

Twig Integration
----------------

[](#twig-integration)

Register the extension:

```
use SensioLabs\AnsiConverter\Bridge\Twig\AnsiExtension;

$twig->addExtension(AnsiExtension());
```

It's possible to use a custom `AnsiToHtmlConverter`:

```
use SensioLabs\AnsiConverter\Bridge\Twig\AnsiExtension;
use SensioLabs\AnsiConverter\Theme\SolarizedTheme;

$theme = new SolarizedTheme();
$converter = new AnsiToHtmlConverter($theme, false);

$twig->addExtension(new AnsiExtension($converter));
```

Then:

```

            {# This is only need if the inline styling is disabled #}
            {{ ansi_css }}

        {{ some_ansi_code|ansi_to_html }}

```

###  Health Score

59

—

FairBetter than 99% of packages

Maintenance46

Moderate activity, may be stable

Popularity63

Solid adoption and visibility

Community39

Small or concentrated contributor base

Maturity75

Established project with proven stability

 Bus Factor1

Top contributor holds 66.7% 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 ~398 days

Recently: every ~718 days

Total

12

Last Release

429d ago

Major Versions

v1.3.0 → v2.0.02025-03-15

PHP version history (4 changes)v1.0.0PHP &gt;=5.3.0

v1.2.0PHP ^7.0

v1.2.1PHP &gt;=7.2.5

v2.0.0PHP &gt;=8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/47313?v=4)[Fabien Potencier](/maintainers/fabpot)[@fabpot](https://github.com/fabpot)

---

Top Contributors

[![fabpot](https://avatars.githubusercontent.com/u/47313?v=4)](https://github.com/fabpot "fabpot (34 commits)")[![jacklul](https://avatars.githubusercontent.com/u/8418678?v=4)](https://github.com/jacklul "jacklul (7 commits)")[![smnandre](https://avatars.githubusercontent.com/u/1359581?v=4)](https://github.com/smnandre "smnandre (2 commits)")[![Jean85](https://avatars.githubusercontent.com/u/6729988?v=4)](https://github.com/Jean85 "Jean85 (1 commits)")[![lyrixx](https://avatars.githubusercontent.com/u/408368?v=4)](https://github.com/lyrixx "lyrixx (1 commits)")[![maxhelias](https://avatars.githubusercontent.com/u/12966574?v=4)](https://github.com/maxhelias "maxhelias (1 commits)")[![skolodyazhnyy](https://avatars.githubusercontent.com/u/576301?v=4)](https://github.com/skolodyazhnyy "skolodyazhnyy (1 commits)")[![adam187](https://avatars.githubusercontent.com/u/156628?v=4)](https://github.com/adam187 "adam187 (1 commits)")[![zoglo](https://avatars.githubusercontent.com/u/55794780?v=4)](https://github.com/zoglo "zoglo (1 commits)")[![cordoval](https://avatars.githubusercontent.com/u/328359?v=4)](https://github.com/cordoval "cordoval (1 commits)")[![jackbentley](https://avatars.githubusercontent.com/u/9383439?v=4)](https://github.com/jackbentley "jackbentley (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/sensiolabs-ansi-to-html/health.svg)

```
[![Health](https://phpackages.com/badges/sensiolabs-ansi-to-html/health.svg)](https://phpackages.com/packages/sensiolabs-ansi-to-html)
```

###  Alternatives

[lavalite/theme

Deafalut theme for lavalite cms.

3324.5k](/packages/lavalite-theme)

PHPackages © 2026

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