Skip to content

Instantly share code, notes, and snippets.

@atsea
Created August 10, 2016 16:47
Show Gist options
  • Select an option

  • Save atsea/a17271a0e1fbdc9010f9dc214c8f8542 to your computer and use it in GitHub Desktop.

Select an option

Save atsea/a17271a0e1fbdc9010f9dc214c8f8542 to your computer and use it in GitHub Desktop.
minify multiple css files on the fly with php.
<?php
/**
* https://ikreativ.com/combine-minify-css-with-php/
* http://stackoverflow.com/questions/9862904/css-merging-with-php
*/
header('Content-type: text/css');
ob_start("compress");
function compress($buffer) {
/* remove comments */
$buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer);
/* remove tabs, spaces, newlines, etc. */
$buffer = str_replace(array("\r\n", "\r", "\n", "\t", ' ', ' ', ' '), '', $buffer);
return $buffer;
}
/* your css files */
include('reset.css');
include('header.css');
include('footer.css');
ob_end_flush();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment