Reputation: 333
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 like to make it look nicer using different colors for different things.
http://cfgfactory.com/images/i/1de3b_colorz.png
Upvotes: 3
Views: 1353
Reputation: 33197
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.
Upvotes: 2
Reputation: 158130
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 :)
Upvotes: 2