- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcssmin.php
More file actions
18 lines (15 loc) · 539 Bytes
/
cssmin.php
File metadata and controls
18 lines (15 loc) · 539 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php
$path = isset($_REQUEST['path']) ? $_REQUEST['path'] : '';
$cssPaths = explode(".css", $path);
header('Content-type: text/css');
foreach ($cssPaths as $cssPath) {
$css = file_get_contents(__DIR__ . '/' . $cssPath . '.css');
echo(compress($css));
}
function compress($css) {
/* remove comments */
$css = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $css);
/* remove tabs, spaces, newlines, etc. */
$css = str_replace(array("\r\n", "\r", "\n", "\t", ' ', ' ', ' '), '', $css);
return $css;
}