开发者

PHP / Linux shell text colors

I was wondering if there's a way of "coloring" the text coming out of php's stdout... (on ubuntu) Basically I've got a scrapping script I made but I'd l开发者_如何学JAVAike to make it look nicer using different colors for different things.

http://cfgfactory.com/images/i/1de3b_colorz.png


You can use the Jm_Console package. It's a library that I wrote on my own.

Features:

  • It supports console colors, console text decorations and has additional features like cursor positioning, or line / screen erasing (clear).

  • You can install it using the pear installer or composer or just download the sources

  • It will work on all Linux or Mac systems and on Windows using ansicon

  • It is well tested and released under the BSD-3 license.

enjoy :)


Use Console Color extension from PEAR


You need to embed ANSI control sequences in your output to change the terminal color:

https://en.wikipedia.org/wiki/ANSI_escape_code

This generally involves the control sequence (ESC(0x1b) + [) and a formatting character, such as ESC + [ + 32 + m

Note that this should be optional, ideally detecting if the stdout is not a terminal and turn off color automatically, as it makes using the output with scripts and log files difficult.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜