如果,使用git时很容易发现是可以在windows的命令行下输出彩色文字的;那么使用php的时候怎么输出多颜色的字体呢;之前找了些linux终端下的方法但对windows来说并不适用
回复内容:
如果,使用git时很容易发现是可以在windows的命令行下输出彩色文字的;那么使用php的时候怎么输出多颜色的字体呢;之前找了些linux终端下的方法但对windows来说并不适用
1.下载dynwrap.dll,https://o0z4bgym5.qnssl.com/dynwrap95.zip
2.解压到%systemroot%\system32
3.cmd运行 regsvr32.exe %systemroot%\system32\dynwrap.dll
确保已开启php_com_dotnet
[php_com_dotnet]extension=php_com_dotnet.dll
demo:
$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, 1);echo 'test text:blue'.php_eol;//默认颜色$com->setconsoletextattribute($ch, 7);echo 'back to normal color!'.php_eol;//绿色$com->setconsoletextattribute($ch, 2);echo 'this is green color text'.php_eol;
颜色代码
7 = >默认值0 = >黑色1 =蓝2 = >绿色3 = >水4 = >红色5 = >紫色6 = >黄7 = >浅灰色8 = >灰色9 = >淡蓝色10 = >浅绿色11 = >淡水12 = >淡红色13 = >浅紫色14 = >淡黄色15 = >白