Created
August 10, 2016 16:47
-
-
Save atsea/a17271a0e1fbdc9010f9dc214c8f8542 to your computer and use it in GitHub Desktop.
minify multiple css files on the fly with php.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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