Clan Adverts

Optimize your CSS style sheet

Description: A simple php function I found to optimize a css style sheet
Version: 1.0
Added on: 27 June 2007
Author: Dmitry-Sh
Difficulty Level: Very Easy
Views: 752
Detailed Profile

Code:
   /**
    * Converts a CSS-file contents into one string
    *
    * @param    string  $t Text data
    * @param    int     $is_debug Skip convertion
    * @return   string  Optimized string
    */
   function text_smooth_css($t, $is_debug = 0)
   {
      if ($is_debug) { return $t; }
      /* Remove comments */
      $t = preg_replace("//*(.*?)*//s", ' ', $t);
      /* Remove new lines, spaces */
      $t = preg_replace("/(s{2,}|[
|
|   | ])/", ' ', $t);
      /* Join rules */
      $t = preg_replace('/([,|;|:|{|}]) /', '\1', $t);
      $t = str_replace(' {', '{', $t);
      /* Remove ; for the last attribute */
      $t = str_replace(';}', '}', $t);
      $t = str_replace(' }', '}', $t);
      return $t;
   }