Compress any text-based content.


/ Published in: PHP
Save to your folder(s)

This function will compress any text-based content.


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.