PHP compressed CSS file sample code
// 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 ();
- ?>
This is implemented using the output buffer function. For more information about this function, see Output Buffer Explained (http://www.phpcodebase.com/php-output-buffering-explained ). |