如果,使用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 = >白