本节内容:
压缩多个CSS文件的Php函数。
例子:
 
<?php
/*
 * 压缩css文件
 * by www.jb200.com
 /*
header('Content-type: text/css');
ob_start("compress");
function compress($buffer) {
  /* remove comments */
  $buffer = preg_replace('!/*[^*]**+([^/][^*]**+)*/!', '', $buffer);
  /* remove tabs, spaces, newlines, etc. */
  $buffer = str_replace(array("rn", "r", "n", "t", '  ', '    ', '    '), '', $buffer);
  return $buffer;
}
/* 加载要压缩的css文件 */
include('master.css');
include('typography.css');
include('grid.css');
include('print.css');
include('handheld.css');
ob_end_flush();
相比这前介绍的 压缩多个CSS与JS文件的php代码 ,这个相对简单一些,适合作为入门参考。