The question A library to convert ANSI escapes (terminal formatting/color codes) to HTML has an answer to this question.
Solution
aha is a Ansi to HTML Adapter written in C. It's available in an Ubuntu
package and on github theZiz/aha.
My code is then simply:
exec("$command | aha", $output, $exitCode);
foreach($output as $k => $line) {
if ($line == '1') { continue; }
echo "$line";
}
Description
aha takes SGR-colored Input and prints W3C conform HTML-Code.
aha reads the Input from a file or stdin and writes HTML-Code to stdout.
There is some nice options:
--black
, -b
: Black Background and white "standard color"
--word-wrap
, -w
: Wrap long lines in the html file. This works with CSS3 supporting browsers as well as many older ones.
--no-header
, -n
: Don't include header into generated HTML, useful for inclusion in full HTML files.