Colorizing Windows command line output from PHP(对 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%system32dynwrap.dll"
您将收到一条成功消息,表示 dynwrap.dll 已注册.
You'll get a success message which means dynwrap.dll is registered.
那么你可以这样使用它:
Then you can use it this way :
$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 => 水色
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 命令行输出进行着色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:对 PHP 的 Windows 命令行输出进行着色


基础教程推荐
- 如何在数学上评估像“2-1"这样的字符串?产生“1"? 2022-01-01
- PHPUnit 的 Selenium 2 文档到底在哪里? 2022-01-01
- php中的PDF导出 2022-01-01
- Web 服务器如何处理请求? 2021-01-01
- 使用 scandir() 在目录中查找文件夹 (PHP) 2022-01-01
- php 7.4 在写入变量中的 Twig 问题 2022-01-01
- php中的foreach复选框POST 2021-01-01
- 主题化 Drupal 7 的 Ubercart “/cart"页 2021-01-01
- 将变量从树枝传递给 js 2022-01-01
- Yii2 - 在运行时设置邮件传输参数 2022-01-01