如何通过PHP实现CSS文件的压缩处理?

更新于
2026-09-26 05:03:24
1阅读来源:SEO教程
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计97个文字,预计阅读时间需要1分钟。

如何通过PHP实现CSS文件的压缩处理?

一次压缩多个CSS文件,输出头部内容:Content-type: text/cssob_start(compress);function compress($buffer) { /* remove comments */ $buffer=preg_replace('/!.*?$/m', '', $buffer); /* remove tabs, spaces, newlines, etc. */}

一次压缩多个CSS文件

如何通过PHP实现CSS文件的压缩处理?

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("\r\n", "\r", "\n", "\t", ' ', ' ', ' '), '', $buffer); return $buffer; } /* your css files */ include('master.css'); include('typography.css'); include('grid.css'); include('print.css'); include('handheld.css'); ob_end_flush();

本文共计97个文字,预计阅读时间需要1分钟。

如何通过PHP实现CSS文件的压缩处理?

一次压缩多个CSS文件,输出头部内容:Content-type: text/cssob_start(compress);function compress($buffer) { /* remove comments */ $buffer=preg_replace('/!.*?$/m', '', $buffer); /* remove tabs, spaces, newlines, etc. */}

一次压缩多个CSS文件

如何通过PHP实现CSS文件的压缩处理?

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("\r\n", "\r", "\n", "\t", ' ', ' ', ' '), '', $buffer); return $buffer; } /* your css files */ include('master.css'); include('typography.css'); include('grid.css'); include('print.css'); include('handheld.css'); ob_end_flush();