Skip to content

Instantly share code, notes, and snippets.

@oiljin
Created May 11, 2016 07:02
Show Gist options
  • Save oiljin/1c2c6f4361f516a822dd5489b9d0c2f6 to your computer and use it in GitHub Desktop.
Save oiljin/1c2c6f4361f516a822dd5489b9d0c2f6 to your computer and use it in GitHub Desktop.
Generating Command Line Colors with PHP
<?php
function colorize($text, $status) {
$out = "";
switch($status) {
case "SUCCESS":
$out = "[42m"; //Green background
break;
case "FAILURE":
$out = "[41m"; //Red background
break;
case "WARNING":
$out = "[43m"; //Yellow background
break;
case "NOTE":
$out = "[44m"; //Blue background
break;
default:
throw new Exception("Invalid status: " . $status);
}
return chr(27) . "$out" . "$text" . chr(27) . "[0m";
}
echo colorize("Your command was successfully executed...", "SUCCESS");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment