Skip to content

Instantly share code, notes, and snippets.

@eddmann
Created March 7, 2014 13:07
Show Gist options
  • Save eddmann/9411127 to your computer and use it in GitHub Desktop.
Save eddmann/9411127 to your computer and use it in GitHub Desktop.
CSS Comp.
<?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