A PHP utility for applying ANSI colors and text styles to console output.
use antibiotics11\AnsiStyler\{AnsiColorCode, AnsiFormatter};
// create a new AnsiFormatter instance
$styler = new AnsiFormatter();
// apply yellow background color, red foreground color and bold style
$formattedText = $styler->withBackgroundColor(AnsiColorCode::BACKGROUND_YELLOW)
->withForegroundColor(AnsiColorCode::FOREGROUND_RED)
->withBold()
->format("Hello, World!");
printf("%s\r\n", $formattedText);
// reinitialize the AnsiFormatter
$styler->initialize();
- PHP >= 8.1
composer require antibiotics11/ansi-styler