使用PHP将ANSI转义序列转换为HTML [英] Converting ANSI escape sequences to HTML using PHP
本文介绍了使用PHP将ANSI转义序列转换为HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这与这个。我想将ANSI转义序列(尤其是颜色)转换为HTML。但是,我想使用PHP完成此操作。有没有执行此操作的库或示例代码?如果没有,有什么可以帮助我实现自定义解决方案的方法?
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?
推荐答案
我在这样的库中不知道PHP。但是,如果您输入的颜色一致且颜色有限,则可以使用简单的 str_replace()
来实现:
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()
:
$dictionary = array(
'ESC[01;34' => '<span style="color:blue">',
'ESC[01;31' => '<span style="color:red">',
'ESC[00m' => '</span>' ,
);
$htmlString = str_replace(array_keys($dictionary), $dictionary, $shellString);
这篇关于使用PHP将ANSI转义序列转换为HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文