php压缩多个CSS/JS文件
1:压缩css
<?php
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;
}
/* your css files */
include('galleria.css');
include('articles.css');
ob_end_flush();使用:
<link href="compress.php" rel="stylesheet" type="text/css" /><span id="tester">test</span>
2:压缩js,利用jsmin类:
来源:http://code.google.com/p/minify/
header('Content-type: text/javascript');
require 'jsmin.php';
echo JSMin::minify(file_get_contents('common.js') . file_get_contents('common2.js')); //phprm.com
本文地址:http://www.phprm.com/develop/fs7642.html
转载随意,但请附上文章地址:-)