Home > Article > Backend Development > About how to compress CSS code in php
This article will explain in detail how to compress CSS code in PHP.
Place the following code in the style.css.php file. Don’t forget to include the css files you need:
<?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(" ", "\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();
Then introduce the php file in the HTML page where the style is introduced:
<link rel="stylesheet" type="text/css" media="screen" href="style.css.php"/>
This article explains how to compress CSS code in PHP. For more related content, please pay attention to the PHP Chinese website.
Related recommendations:
PHP receives json and inserts the received data into the database
Processing Protocol Buffers data in PHP
The above is the detailed content of About how to compress CSS code in php. For more information, please follow other related articles on the PHP Chinese website!