<?php ob_start('ob_gzhandler'); header('Content-Type: text/css'); function compress($buffer) { /* remove comments */ $buffer = preg_replace('!/*[^*]**+([^/][^*]**+)*/!', '', $buffer); /* remove tabs and newlines, etc. */ $buffer = str_replace(array("rn", "r", "n", "t"), '', $buffer); /* remove unnecessary whitspaces */ $buffer = preg_replace('#[s]{2,}#', ' ', $buffer); return $buffer; } /* your css files */ if(isset($_GET['css']) && file_exists($_GET['css'])) { echo compress(file_get_contents($_GET['css'])); } ob_end_flush(); ?>
مثالی از نحوه استفاده:
<link href="csscompress.php?css=style.css" rel="stylesheet" type="text/css"/>