This php paste was created by Gabriel on 2010-07-30 10:22:19.
  1. <?php
  2.  
  3. // CSS files to compress
  4. $files = array(
  5. 'styles/reset.css',
  6. 'styles/style.css',
  7. );
  8.  
  9. // Etag
  10. $etag = '';
  11. foreach($files as $file){ if(is_readable($file)){ $etag .= filemtime($file); } }
  12. $etag = md5($etag);
  13.  
  14. // Check Etag
  15. if(isset($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] == $etag){
  16. header('HTTP/1.1 304 Not Modified');
  17. header('Content-Length: 0');
  18. exit();
  19. }
  20.  
  21. // Headers
  22. header('Content-type: text/css');
  23. header('Etag: '.$etag);
  24. ob_start("compress");
  25.  
  26. // Compress buffer
  27. function compress($buffer) {
  28. // remove comments
  29. $buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer);
  30. // remove tabs, spaces, newlines, etc.
  31. $buffer = str_replace(array("\r\n", "\r", "\n", "\t", ' ', ' ', ' '), '', $buffer);
  32. $buffer = str_replace(array(', ',' {','} ','{ ',' }',': ','; '), array(',','{','}','{','}',':',';'), $buffer);
  33. return $buffer;
  34. }
  35.  
  36. // Include CSS files
  37. foreach($files as $file){ if(is_readable($file)){ include($file); } }
  38.  
  39. // Flush
  40. ob_end_flush();