Add Colours to PHP CLI output
This is a stand alone class and can be used as it is.
Colourout\Colour::paint("This is a sample string", Colour::BLUE);
will return the string in blue
Colourout\Colour::paint("This is a sample string", Colour::GREY, Colour::RED);
will return the string in grey text with red background
- Note: Paint will not print anything to console. This is useful only to colour the string. You can use
echo
or use other methods explained below
Colourout\Colour::print("This is a sample string", Colour::GREEN, Colour::YELLOW);
will print the string in green text colour and yellow background
println
will print with a new line.
- Presets are predefined colour combinations.
Colourout\Colour::printError($errorString, $boldText, $printToConsole)
will print the error string in grey text and red background. The text can be made bold by sending true
as the second parameter.
Its default value depends on the preset.
$printToConsole
is set to true by default. If sent as false, nothing will be printed to the console.
All the methods return strings.
Colourout\Colour::paint($string, $textColour, $backgroundColour);
Colourout\Colour::print($string, $textColour, $backgroundColour);
Colourout\Colour::println($string, $textColour, $backgroundColour);
Colourout\Colour::printError($string, $boldText, $printToConsole);
Colourout\Colour::printInfo($string, $boldText, $printToConsole);
Colourout\Colour::printWarning($string, $boldText, $printToConsole);
Colourout\Colour::getAvailableTextColours($printToConsole);
returns an array of text colours supported by this class
Colourout\Colour::getAvailableBackgroundColours($printToConsole);
returns an array of background colours supported by this class
- Notes:
$printToConsole
istrue
by default. It will also return the array of colours- Your console might support more colours than this class.