3v4l.org

run code in 300+ PHP versions simultaneously
<?php Class App_Messages{ protected static $ANSI_CODES = array( "Reset" => 0, "Bold" => 1, "Italic" => 3, "Underline" => 4, "Blink" => 5, "Inverse" => 7, "Hidden" => 8, "BLK" => 30, "RED" => 31, "GRN" => 32, "YEL" => 33, "BLU" => 34, "PUR" => 35, "CYN" => 36, "WHT" => 37, "BLK_bg" => 40, "RED_bg" => 41, "GRN_bg" => 42, "YEL_bg" => 43, "BLU_bg" => 44, "PUR_bg" => 45, "CYN_bg" => 46, "WHT_bg" => 47 ); public static function printToScreen($message,$format = NULL) { echo EOL.self::set($message,$format).EOL; } public static function set($str, $color = NULL) { if (!isset($color)) { return $str; } $color_attrs = explode("+", $color); $ansi_str = ""; foreach ($color_attrs as $attr) { $ansi_str .= "\033[" . self::$ANSI_CODES[$attr] . "m"; } $ansi_str .= $str . "\033[" . self::$ANSI_CODES["Reset"] . "m"; return $ansi_str; } public static function replace($full_text, $search_regexp, $color) { $new_text = preg_replace_callback( "/($search_regexp)/", function ($matches) use ($color) { return App_Messages::set($matches[1], $color); }, $full_text ); return is_null($new_text) ? $full_text : $new_text; } } App_Messages::printToScreen("HELLO","BLU+Bold");

preferences:
65.07 ms | 402 KiB | 5 Q