0

Is there anyway to change console color from an echoed PHP statement in debian? I've got a script that runs from the command line of a debian sever and i'm trying to figure out view all the outputted information in a clearer fashion.

1 Answers1

2

Yes you can easily change the color of the output. That is, when the terminal supports it.

You can do this manually, as follows:

echo "\033[31m some colored text \033[0m some white text \n";
echo "\033[32m some colored text \033[0m some white text \n";

Or use a more sophisticated way with a library such as https://github.com/kevinlebrun/colors.php or https://github.com/abcarroll/simple-ansi-escape where you can have more understandable code, such as

echo $c('Hello World!')->white()->bold()->highlight('green') . PHP_EOL;

or

echo esc::ansiEscape(array('color/blue', 'faint', 'underline')), "I hope you enjoy Simple-Ansi-Escape!");

Hope that helps!

mark
  • 344
  • 3
  • 8