Skip to content

Instantly share code, notes, and snippets.

@cbednarski
Created October 9, 2012 02:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cbednarski/3856190 to your computer and use it in GitHub Desktop.
Save cbednarski/3856190 to your computer and use it in GitHub Desktop.
Terminal colors with PHP
<?php
// Based on info from:
// - http://www.sitepoint.com/forums/showthread.php?398020-terminal-colors-in-PHP
// - http://www.dzone.com/snippets/colorized-text-php-unix
$colors = array(
'light_red' => "[1;31m",
'light_green' => "[1;32m",
'yellow' => "[1;33m",
'light_blue' => "[1;34m",
'magenta' => "[1;35m",
'light_cyan' => "[1;36m",
'white' => "[1;37m",
'normal' => "[0m",
'black' => "[0;30m",
'red' => "[0;31m",
'green' => "[0;32m",
'brown' => "[0;33m",
'blue' => "[0;34m",
'cyan' => "[0;36m",
'bold' => "[1m",
);
// To output the color character you need the chr(27) control character to be
// output before the color code, e.g.:
echo chr(27).$colors['light_red'].'Hello World'.PHP_EOL;
echo chr(27).$colors['light_cyan'].'Hello World'.PHP_EOL;
echo chr(27).$colors['light_green'].'Hello World'.PHP_EOL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment