3

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

3 Answers 3

2

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 :)

Sign up to request clarification or add additional context in comments.

Comments

2

Use Console Color extension from PEAR

Comments

2

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.