当前位置:Gxlcms > PHP教程 > php压缩CSS文件

php压缩CSS文件

时间:2021-07-01 10:21:17 帮助过:25人阅读

一次压缩多个CSS文件

  1. header('Content-type: text/css');
  2. ob_start("compress");
  3. function compress($buffer) {
  4. /* remove comments */
  5. $buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer);
  6. /* remove tabs, spaces, newlines, etc. */
  7. $buffer = str_replace(array("\r\n", "\r", "\n", "\t", ' ', ' ', ' '), '', $buffer);
  8. return $buffer;
  9. }
  10. /* your css files */
  11. include('master.css');
  12. include('typography.css');
  13. include('grid.css');
  14. include('print.css');
  15. include('handheld.css');
  16. ob_end_flush();

php, CSS

人气教程排行