Advertisement
DArcher

OTF CSS Compressor

Dec 10th, 2014
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.16 KB | None | 0 0
  1. <?php
  2. //CSS Compressor
  3. //By: Donnie Archer
  4. //v1.0.0
  5. header("Content-type: text/css");
  6. /*
  7.  * Set this to true so it will separate the content by files and not compress it.
  8.  */
  9. $disable = false;
  10. /*
  11.  * Too add stylesheets not in this dir, add the paths to the otherStylesheets array
  12.  */
  13.  
  14. $otherStylesheets = array();
  15. $otherStylesheets[] = "layout.css";
  16. $otherStylesheets[] = "menu.css";
  17. $otherStylesheets[] = "sidebar-menu.css";
  18. $otherStylesheets[] = "layout-full-span.css";
  19. $otherStylesheets[] = "custom.css";
  20.  
  21. $css = "";
  22.  
  23. //Uncomment the following line to auto scan the directory this file is in and import those css files.
  24. //$stylesheets = scandir(__DIR__);
  25.  
  26. if(is_array($stylesheets)){
  27.     $stylesheets = array_merge($stylesheets,$otherStylesheets);
  28. }else{
  29.     $stylesheets = $otherStylesheets;
  30. }
  31.  
  32. foreach($stylesheets AS $x => $file){
  33.     if(preg_match("/\.css/",$file)){
  34.         if($disable){
  35.             $css .= "\n\n/*{$file}/*\n";
  36.         }
  37.         $css .= file_get_contents($file);
  38.     }
  39. }
  40.  
  41. if(!$disable){
  42.     $css = str_replace(array("\n","\t","\r"),"",$css);
  43.     $css = preg_replace("/\/\*[a-z0-9:]+\*\//i", "", $css);
  44. }
  45.  
  46. echo $css;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement