着色从PHP的Windows命令行输出 [英] Colorizing Windows command line output from PHP

查看:188
本文介绍了着色从PHP的Windows命令行输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要在bash中输出彩色文本,请使用 ANSI转义序列

To output colored text in bash, you use ANSI escape sequences.

如何在Windows命令行,特别是从PHP输出彩色文本?

How do you output colored text on a Windows command line, specifically from PHP?

推荐答案

从以下位置下载dynwrap.dll: http://www.script-coding.com/dynwrap95.zip

Download dynwrap.dll from : http://www.script-coding.com/dynwrap95.zip

然后将其解压缩到%systemroot%\system32 目录,然后在命令行中运行以下命令:

Then extract it to %systemroot%\system32 directory and then run following command in command line:

regsvr32.exe%systemroot%\system32\dynwrap.dll

您会收到一条成功消息,表示注册了dynwrap.dll。

You'll get a success message which means dynwrap.dll is registered.

然后您可以这样使用:

$com = new COM('DynamicWrapper');

// register needed features
$com->Register('kernel32.dll', 'GetStdHandle', 'i=h', 'f=s', 'r=l');
$com->Register('kernel32.dll', 'SetConsoleTextAttribute', 'i=hl', 'f=s', 'r=t');

// get console handle
$ch = $com->GetStdHandle(-11);

某些示例:

$com->SetConsoleTextAttribute($ch, 4);
echo 'This is a red text!';
$com->SetConsoleTextAttribute($ch, 7);
echo 'Back to normal color!';

颜色代码:

7 =>

0 =>黑色

1 =>蓝色

2 =>绿色

3 => aqua

4 =>红色

5 =>紫色

6 =>黄色

7 =>浅灰色

8 =>灰色

9 =>浅蓝色

10 =>浅绿色

11 =>浅水色

12 =>淡红色

13 =>淡紫色

14 =>淡黄色

15 =>白色

colors codes:
7 => default
0 => black
1 => blue
2 => green
3 => aqua
4 => red
5 => purple
6 => yellow
7 => light gray
8 => gray
9 => light blue
10 => light green
11 => light aqua
12 => light red
13 => light purple
14 => light yellow
15 => white

这篇关于着色从PHP的Windows命令行输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆