This is a similar question to this one. I would like to convert ANSI escape sequences, especially for color, into HTML. However, I would like to accomplish this using PHP. Are there any libraries or example code out there that do this? If not, anything that can get me part way to a custom solution?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Is there a way to play audio on a mobile browser w
I don't know of any such library in PHP. But if you have a consistent input with limited colors, you can accomplish it using a simple
str_replace()
:There are library now: ansi-to-html
And very easy to use:
The str_replace solution wouldn't work in cases where colors are "nested", because in ANSI color codes, one ESC[0m reset is all that's needed to reset all attributes. While in HTML, you need the exact number of SPAN closing tags.
A workaround that works the "nested" use case is below:
(taken from my Drush Terminal issue here: http://drupal.org/node/709742 )
I'm also looking for the PHP library to do this easily.
P.S. If you want to convert ANSI escape sequences to PNG/image, you can use AnsiLove.