onsa
2/20/2017 - 1:37 PM

Singlicate CSS

Singlicate CSS

<?php

/*	
	This script cleans up duplicates in CSS files:
		1. Standardise your code by pushing it through http://www.cleancss.com/css-beautify/
		2. Put the new file name and path in place of 'input.css' below
		3. Run the script
		4. Tada, you have an output.css that awaits only minification.
 */

$output = fopen("output.css", "w") or die("Can't create file");
$cssClean = array_unique(preg_split("/(?<=\n}\n)/", file_get_contents('input.css')));       //  parse file into chunks ending in newline-}-newline & delete duplicates
foreach($cssClean as $line) {fwrite($output, $line);}
fclose($output);