Created
March 7, 2014 13:07
-
-
Save eddmann/9411127 to your computer and use it in GitHub Desktop.
CSS Comp.
This file contains 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 | |
define('CSS', '/css/compiled'); | |
define('CSS_PATH', realpath(__DIR__ . '/css')); | |
define('CSS_COMPILED', realpath(CSS_PATH . '/compiled')); | |
function css($css) | |
{ | |
$name = md5(implode('', $css)) . '.css'; | |
if ( ! is_file(CSS_COMPILED . '/' . $name)) { | |
$out = ''; | |
foreach ($css as $file) { | |
$out .= file_get_contents(CSS_PATH . '/' . $file); | |
} | |
$out = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $out); | |
$out = str_replace(': ', ':', $out); | |
$out = str_replace(array("\r\n", "\r", "\n", "\t", ' ', ' ', ' '), '', $out); | |
file_put_contents(CSS_COMPILED . '/' . $name, $out); | |
} | |
return CSS . '/' . $name; | |
} | |
echo css(['body.css', 'h1.css', 'p.css']); | |
echo css(['body.css', 'p.css']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment