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

WBOY
发布: 2016-07-25 08:55:28
原创
911 人浏览过
  1. /*

  2. * 压缩css文件
  3. * by bbs.it-home.org
  4. /*
  5. header('Content-type: text/css');
  6. ob_start("compress");
  7. function compress($buffer) {
  8. /* remove comments */
  9. $buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer);
  10. /* remove tabs, spaces, newlines, etc. */
  11. $buffer = str_replace(array("\r\n", "\r", "\n", "\t", ' ', ' ', ' '), '', $buffer);
  12. return $buffer;
  13. }
  14. /* 加载要压缩的css文件 */

  15. include('master.css');
  16. include('typography.css');
  17. include('grid.css');
  18. include('print.css');
  19. include('handheld.css');
  20. ob_end_flush();

复制代码

相比这前介绍的 压缩多个CSS与JS文件的php代码 ,这个相对简单一些,适合作为入门参考。



来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!