問題描述
要在 bash 中輸出彩色文本,您可以使用 ANSI 轉(zhuǎn)義序列.
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
這篇關(guān)于對 PHP 的 Windows 命令行輸出進行著色的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!