Skip to content

Instantly share code, notes, and snippets.

@kasperhartwich
Created September 3, 2014 09:27
Show Gist options
  • Select an option

  • Save kasperhartwich/36d9069403a133ef1394 to your computer and use it in GitHub Desktop.

Select an option

Save kasperhartwich/36d9069403a133ef1394 to your computer and use it in GitHub Desktop.
Color CLI text in ansicolors. See http://en.wikipedia.org/wiki/ANSI_escape_code
function ansicolor($text , $color='cyan', $background = false, $bold = false) {
$colorcodes = array('black' => 0, 'red' => 1, 'green' => 2, 'yellow' => 3, 'blue' => 4, 'magenta' => 5, 'cyan' => 6, 'white' => 7);
return ($bold ? chr(27) . "[1m" : "") . chr(27) . "[" . ($background ? '4' : '3') . $colorcodes[$color] . "m" . $text . chr(27) . "[0m";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment