3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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");
based on NNea7
Output for 7.2.0
Warning: Use of undefined constant EOL - assumed 'EOL' (this will throw an Error in a future version of PHP) in /in/QYEp7 on line 32 Warning: Use of undefined constant EOL - assumed 'EOL' (this will throw an Error in a future version of PHP) in /in/QYEp7 on line 32 EOLHELLOEOL
Output for 5.3.0 - 7.1.10
Notice: Use of undefined constant EOL - assumed 'EOL' in /in/QYEp7 on line 32 Notice: Use of undefined constant EOL - assumed 'EOL' in /in/QYEp7 on line 32 EOLHELLOEOL
Output for 5.1.0 - 5.2.17
Parse error: syntax error, unexpected T_FUNCTION in /in/QYEp7 on line 61
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_FUNCTION in /in/QYEp7 on line 61
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/QYEp7 on line 5
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/QYEp7 on line 5
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/QYEp7 on line 5
Process exited with code 255.