教程集 www.jiaochengji.com
教程集 >  脚本编程  >  php  >  正文 php 压缩多个CSS文件的实现代码

php 压缩多个CSS文件的实现代码

发布时间:2017-07-10   编辑:jiaochengji.com
分享一例php代码,实现在线压缩多个CSS文件,有需要的朋友参考学习下。

本节内容:
压缩多个CSS文件的Php函数。

例子:
 

复制代码 代码示例:

<?php
/*
 * 压缩css文件
 * by www.jbxue.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("\r\n", "\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代码 ,这个相对简单一些,适合作为入门参考。

您可能感兴趣的文章:
php 压缩多个CSS文件的实现代码
PHP压缩CSS文件示例代码
PHP开启gzip压缩的二种方法
lighttpd配置压缩文件(mod_compress)
apache启用gzip压缩方法
php压缩函数(gzcompress gzuncompress)压缩字符串
php gzip压缩js与css代码的例子
IIS压缩及性能优化
iis中不能开启Gzip压缩的问题
教你修改Apache配置文件开启gzip压缩传输

[关闭]
~ ~