Created
April 26, 2017 22:31
-
-
Save Bujhm/ce7cc8e9466888dc23b42b17bcf32173 to your computer and use it in GitHub Desktop.
Generating Command Line Colors with PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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