Simple CSS Compresion Using PHP

php, css, html

The is a simple php script to compress css files together. It uses two files. A PHP file and a .htacess file.

				$css = "";
				$root = $_SERVER["DOCUMENT_ROOT"] . "/css/"; //directory where the css lives
				$files = explode(",", $_SERVER["QUERY_STRING"]);
				if(sizeof($files))
				{
					foreach($files as $file)
					{
						$css.= (is_file($root . $file . ".css") ? file_get_contents($root . $file . ".css") : "");
					}
				}

				return str_replace("; ", ";", str_replace(" }", "}", str_replace("{ ", "{", str_replace(array("\r\n", "\r", "\n", "\t", "  ", "    ", "    "), "", preg_replace("!/\*[^*]*\*+([^/][^*]*\*+)*/!", "", $css)))));
			

Here is the .htacess file.

				
					SetHandler  application/x-httpd-php
				
			

Here is how to use it.