3v4l.org

run code in 300+ PHP versions simultaneously
<?php function minimize($file) { return preg_replace('#(<\?php)\s+#S','$1 ',preg_replace('#\s*([(){}[\];,.:+<>*/%^=&?|$-])\s*#S', '$1', array_reduce(token_get_all(php_strip_whitespace($file)),function($c,$x){ static $s = [], $i=0; if ( is_string($x) ) return $c . $x; $_ = $x[1]; switch($x[0]){ case T_STRING: return $c . (defined($_) ? (is_bool($k=constant($_))||is_null($k)?$_:$k) : $_); case T_VARIABLE: return $c . (empty($s[$_]) ? ($s[$_] = '$_' . base_convert($i++,10,36)) : $s[$_]); case T_LOGICAL_OR: return $c . '||'; case T_LOGICAL_AND: return $c . '&&'; default: return $c . $_; } }))); } echo minimize(__FILE__);

preferences:
39.86 ms | 402 KiB | 5 Q