This is buggy, don't use it!
<?php $content=file_get_contents($_SERVER['QUERY_STRING']); $prot_search=$prot_replace=array(); //protect strings and keywords $content=preg_replace_callback(array('|\\"|','|\\\'|','|\".+\"|','|\'.+\'|'),'cut_unparsed',$content); //strip comments $content=preg_replace(array('|/\*.*\*/|ms','|//.*$|m'),'',$content); //protect regex $content=preg_replace_callback('|/.+/|','cut_unparsed',$content); //strip spaces $content=preg_replace(array('|^\s*|m','|(\w\s+[\$\w\'%])?\s*|','|;(\})|'),'${1}',$content); $content=str_replace($prot_search,$prot_replace,$content); echo $content; function cut_unparsed($matches) { global $prot_replace,$prot_search; $prot_replace[]=$matches[0]; return ($prot_search[]='~'.count($prot_replace).'~'); } ?>
preg_replace_callback | (PHP 4 >= 4.0.5, PHP 5) |
preg_replace | (PHP 4, PHP 5) |
str_replace | (PHP 4 >= 4.0.5, PHP 5) |
file_get_contents | (PHP 4 >= 4.3.0, PHP 5) |