// This defines the header type - header("Content-type: text/css");
-
- // Start the output buffer
- ob_start("compress_css");
-
- // Function which actually compress
- // The CSS file
- function compress_css($buffer)
- {
- /* remove comments */
- $buffer = preg_replace("!/\*[^*]*\*+([^/][^*]*\*+)*/!", "", $buffer) ;
- /* remove tabs, spaces, newlines, etc. */
- $arr = array("\r\n", "\r", "\n", "\t", " ", " ", " ") ;
- $buffer = str_replace($arr, "", $buffer) ;
- return $buffer;
- }
/* include all CSS files */ - include("style.css");
- include("fonts.css");
- include("print.css");
// Flush the output buffer - ob_end_flush();
- ?>
此使用了output buffer函数来实现,此函数说明,请参考:Output Buffer Explained(http://www.phpcodebase.com/php-output-buffering-explained/)。 |