Posted By

o0110o on 10/21/12


Tagged

css javascript php compress


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

o0110o


Compress any text-based content.


 / Published in: PHP
 

This function will compress any text-based content.

  1. function crush($_file) {
  2. $_file = preg_replace(array("/((?:\/\*(?:[^*]|(?:\*+[^*\/]))*\*+\/)|(?:\/\/.*))/","!/\*[^*]*\*+([^/][^*]*\*+)*/!"), "", $_file); /* remove comments */
  3. $_file = str_replace(array('
  4. ','\r','\t','\n',' ',' ',' '), '', $_file); /* remove tabs, spaces, newlines, etc. */
  5. /* remove spaces before/after certain characters */
  6. $_file = preg_replace(array('(( )+\))','(\)( )+)'), ')', $_file); $_file = preg_replace(array('(( )+\()','(\(( )+)'), '(', $_file);
  7. $_file = preg_replace(array('(( )+\})','(\}( )+)'), '}', $_file); $_file = preg_replace(array('(( )+\{)','(\{( )+)'), '{', $_file);
  8. $_file = preg_replace(array('(( )+\:)','(\:( )+)'), ':', $_file); $_file = preg_replace(array('(( )+\;)','(\;( )+)'), ';', $_file);
  9. $_file = preg_replace(array('(( )+\,)','(\,( )+)'), ',', $_file); return $_file;
  10. }

Report this snippet  

You need to login to post a comment.