PHP implementation code for compressing multiple CSS files

WBOY
Release: 2016-07-25 08:55:28
Original
966 people have browsed it
  1. /*

  2. * Compress css file
  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("rn", "r", "n", "t ", ' ', ' ', ' '), '', $buffer);
  12. return $buffer;
  13. }

  14. /* Load the css file to be compressed*/

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

Copy code

Compared with the php code for compressing multiple CSS and JS files introduced before, this one is relatively simple and suitable for use as Getting Started Reference.



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template