Skip to content

Instantly share code, notes, and snippets.

@apphp-snippets
Created February 11, 2013 08:32
Show Gist options
  • Select an option

  • Save apphp-snippets/4753256 to your computer and use it in GitHub Desktop.

Select an option

Save apphp-snippets/4753256 to your computer and use it in GitHub Desktop.
<?php
// source: http://www.apphp.com/index.php?snippet=php-compress-multiple-css-files
header('Content-type: text/css');
ob_start('compress_css');
function compress_css($buffer) {
/* remove comments in css file */
$buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer);
/* also remove tabs, spaces, newlines, etc. */
$buffer = str_replace(array("\r", "\n", "\r\n", "\t", ' ', ' ', ' '), '', $buffer);
return $buffer;
}
/* a list of your css files */
include('style.css');
include('css/menu.css');
include('css/typography.css');
include('css/print.css');
include('inc/css/footer.css');
ob_end_flush();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment