Created
October 26, 2012 16:04
-
-
Save abbotto/3959645 to your computer and use it in GitHub Desktop.
Compress Any Text-Based Content.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function crush($_file) { | |
$_file = preg_replace(array("/((?:\/\*(?:[^*]|(?:\*+[^*\/]))*\*+\/)|(?:\/\/.*))/","!/\*[^*]*\*+([^/][^*]*\*+)*/!"), "", $_file); /* remove comments */ | |
$_file = str_replace(array('\r\n','\r','\t','\n',' ',' ',' '), '', $_file); /* remove tabs, spaces, newlines, etc. */ | |
/* remove spaces before/after certain characters */ | |
$_file = preg_replace(array('(( )+\))','(\)( )+)'), ')', $_file); $_file = preg_replace(array('(( )+\()','(\(( )+)'), '(', $_file); | |
$_file = preg_replace(array('(( )+\})','(\}( )+)'), '}', $_file); $_file = preg_replace(array('(( )+\{)','(\{( )+)'), '{', $_file); | |
$_file = preg_replace(array('(( )+\:)','(\:( )+)'), ':', $_file); $_file = preg_replace(array('(( )+\;)','(\;( )+)'), ';', $_file); | |
$_file = preg_replace(array('(( )+\,)','(\,( )+)'), ',', $_file); return $_file; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment