Posted By

iTony on 04/07/10


Tagged

php gzip compress


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

BrianCoyDesign
dantreacy


gzip files in php


 / Published in: PHP
 

  1. <?php
  2. if(extension_loaded('zlib')){
  3. ob_start('ob_gzhandler');
  4. }
  5. header ('content-type: text/css; charset: UTF-8');
  6. header ('cache-control: must-revalidate');
  7. $offset = 60 * 60;
  8. $expire = 'expires: ' . gmdate ('D, d M Y H:i:s', time() + $offset) . ' GMT';
  9. header ($expire);
  10. ob_start('compress');
  11. function compress($buffer) {
  12. // remove comments
  13. $buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer);
  14. return $buffer;
  15. }
  16.  
  17. // list CSS files to be included
  18. include('baseline.css');
  19. include('styles.css');
  20.  
  21. ?>

Report this snippet  

You need to login to post a comment.