3v4l.org

run code in 300+ PHP versions simultaneously
<?php function prepareForOutput($content, $exclude=[]) { $replacements = [ "\r" => '\r', "\n" => '\n', "\t" => '\t', " " => '·', ]; if (stripos(PHP_OS, 'WIN') === 0 && PHP_VERSION_ID < 70100) { // Do not replace spaces on old PHP on Windows. // Printing Unicode characters like '·' to Windows console only works since PHP 7.1. unset($replacements[" "]); } $replacements = array_diff_key($replacements, array_fill_keys($exclude, true)); // Colour runs of invisible characters. $match = implode('', array_keys($replacements)); $content = preg_replace("/([$match]+)/", "\033[30;1m$1\033[0m", $content); $content = strtr($content, $replacements); return $content; } for ($i = 0; $i < 10000; $i++) { prepareForOutput('{echo 1;}', ["\r"]); }

preferences:
26.94 ms | 410 KiB | 5 Q