php在windows命令列下輸出彩色文字的方法

來源:互聯網
上載者:User

如果,使用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 = >白
  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.