Description
This small library only does one thing: converting a text containing ANSI codes to an HTML5 fragment:
ANSI to HTML5 alternatives and similar libraries
Based on the "Strings" category.
Alternatively, view ANSI to HTML5 alternatives based on common mentions on social networks and blogs.
-
Mobile-Detect
Mobile_Detect is a lightweight PHP class for detecting mobile devices (including tablets). It uses the User-Agent string combined with specific HTTP headers to detect the mobile environment. -
SQL Formatter
A lightweight php class for formatting sql statements. Handles automatic indentation and syntax highlighting. -
Device Detector
The Universal Device Detection library will parse any User Agent and detect the browser, operating system, device used (desktop, tablet, mobile, tv, cars, console, etc.), brand and model. -
Slugify
Converts a string to a slug. Includes integrations for Symfony, Silex, Laravel, Zend Framework 2, Twig, Nette and Latte. -
Jieba-PHP
"結巴"中文分詞:做最好的 PHP 中文分詞、中文斷詞組件。 / "Jieba" (Chinese for "to stutter") Chinese text segmentation: built to be the best PHP Chinese word segmentation module. -
URLify
A fast PHP slug generator and transliteration library that converts non-ascii characters for use in URLs. -
Google Translate For Free
Library for free use Google Translator. With attempts connecting on failure and array support. -
Case converter
Convert strings between 13 naming conventions: Snake case, Camel case, Kebab case, Pascal case, Ada case, Train case, Cobol case, Macro case, Upper case, Lower case, Title case, Sentence case and Dot notation. -
Russian metaphone phonetic algorithm implementation for PHP
Russian metaphone algorithm implementation
CodeRabbit: AI Code Reviews for Developers

* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of ANSI to HTML5 or a related project?
README
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:
<html>
<body>
<pre style="background-color: black; overflow: auto; padding: 10px 15px; font-family: monospace;"
><?php echo $html ?></pre>
</body>
</html>
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:
<html>
<head>
<style>
<?php echo $styles ?>
.ansi_box { overflow: auto; padding: 10px 15px; font-family: monospace; }
</style>
</head>
<body>
<pre class="ansi_color_bg_black ansi_color_fg_white ansi_box"><?php echo $html ?></pre>
</body>
</html>
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(AnsiExtension($converter));
Then:
<html>
<head>
<style>
{# This is only need if the inline styling is disabled #}
{{ ansi_css }}
</style>
</head>
<body>
{{ some_ansi_code|ansi_to_html }}
</body>
</html>