Return to Snippet

Revision: 30305
at August 11, 2010 17:41 by Sverri


Updated Code
/*

  USING THIS FILE

  1. Add the CSS files you want included to the $file array. */

  $file[] = 'reset.css';
  $file[] = 'typography.css';
  $file[] = 'design.css';

/*
  2. Save this file.

  3. Point your HTML files to this script, eg.
     <link rel="stylesheet" href="/this-file.php" />

  4. Save the HTML file and refresh browser.

*/

header('Content-type: text/css; Charset=utf-8');

function minifyCSS($f)
{
  return preg_replace(array('/\/\*[\s\S]*?\*\//','/\s*([;:{},>+])\s*/',
  '/;}/','/\r?\n/'),array('','\1','}',''),file_get_contents($f));
}
foreach ($file as $name)
{
  if (file_exists($name))
  {
    echo minifyCSS($name);
  }
}

Revision: 30304
at August 11, 2010 17:36 by Sverri


Updated Code
/*

  USING THIS FILE

  1. Add the CSS files you want included to the $file array. */

  $file[] = 'reset.css';
  $file[] = 'typography.css';
  $file[] = 'design.css';

/*
  2. Save this file.

  3. Point your HTML files to this script, eg.
     <link rel="stylesheet" href="/this-file.php" />

  4. Save the HTML file and refresh browser.

*/

header('Content-type: text/css; Charset=utf-8');

function minifyCSS($f)
{
  return preg_replace(array('/\/\*[\s\S]*?\*\//','/\s*([\;\:\{\}\,\>\+])\s*/',
  '/\;\}/','/\r?\n/'),array('','\1','}',''),file_get_contents($f));
}
foreach ($file as $name)
{
  if (file_exists($name))
  {
    echo minifyCSS($name);
  }
}

Revision: 30303
at August 11, 2010 16:36 by Sverri


Initial Code
/*

  USING THIS FILE

  1. Add the CSS files you want included to the $file array. */

  $file[] = 'reset.css';
  $file[] = 'typography.css';
  $file[] = 'design.css';

/*
  2. Save this file.

  3. Point your HTML files to this script, eg.
     <link rel="stylesheet" href="/this-file.php" />

  4. Save the HTML file and refresh browser.

*/

header('Content-type: text/css; Charset=utf-8');

function minifyCSS($f)
{
  return preg_replace(array('/\/\*[\s\S]*?\*\//','/(\s+)?([\;\:\{\}\,\>\+])(\s+)?/',
  '/\;\}/','/\r?\n/'),array('','\2','}',''),file_get_contents($f));
}
foreach ($file as $name)
{
  if (file_exists($name))
  {
    echo minifyCSS($name);
  }
}

Initial URL

                                

Initial Description
Minify and combine CSS files. Instructions in code.

Initial Title
Minify and combine CSS files

Initial Tags

                                

Initial Language
PHP