<?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];
if ( $x[0] == 310 ) return $c . (defined($_) ? (is_bool($k=constant($_))||is_null($k)?$_:$k) : $_);
if ( $x[0] == 312 ) return $c . (empty($s[$_]) ? ($s[$_] = '$_' . base_convert($i++,10,36)) : $s[$_]);
if ( $x[0] == 263 ) return $c . '||';
if ( $x[0] == 265 ) return $c . '&&';
return $c . $_;
})));
}
echo minimize(__FILE__);
preferences:
37.54 ms | 402 KiB | 5 Q