Skip to content

Instantly share code, notes, and snippets.

@Bujhm
Created April 26, 2017 22:31
Show Gist options
  • Save Bujhm/ce7cc8e9466888dc23b42b17bcf32173 to your computer and use it in GitHub Desktop.
Save Bujhm/ce7cc8e9466888dc23b42b17bcf32173 to your computer and use it in GitHub Desktop.
Generating Command Line Colors with PHP
<?php
/**
* Generating Command Line Colors with PHP
* @author Mario Awad
* @link http://softkube.com/blog/generating-command-line-colors-with-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