Blog

How To: Create a Simple CSS Compressor using PHP

CSS or Cascading Style Sheets is a language used to describe the presentation of a document written in a markup language. If you’re developing a very complex design for your site, CSS scripts become very long, and takes too much time to load. But a compressed CSS script can help your website load faster and easily maintain its functionality. Here, I’ve created a very simple CSS compressor using PHP to compress or reduce CSS script size.

The Simple CSS Compressor

Please click the flowing links for test and download Simple CSS Compressor Script.

The process takes place in a .php file which I call index.php.. Follow these step to create a simple Css compressor.

  1. Main function

    Create a index.php file and add this function into it. This function is the main part of our CSS compressor. It will remove comments, white spaces and line breaks from your CSS script.

  2. CSS input form

    Add this form into your index.php file. By this form you can submit your CSS script for compress.

  3. Display Compressed CSS

    Add this code wherever you want in your index.php file. It will display the compressed CSS script.

Please follow above links to test and download this script. If you have any bug report or suggestion for my script please comment it below. Please share with your friends if you like this script.