<?php // fichier css source $file = 'doorgets.css'; if(!is_file($file)){ echo $file .' not found'; exit(); } // fichier css de destination $fileCompressed = 'doorGetsCompress_'.$file; $fileContent = file_get_contents($file); $eContent = explode('}', $fileContent ); foreach ($eContent as $key => $value) { $eContent[$key] = trim($value," \t\n\r\0\x0B"); } foreach ($eContent as $key => $value) { $eContent[$key] = explode('{', $value ); if( empty($eContent[$key]) || count($eContent[$key]) !== 2 || empty($eContent[$key][0]) ){ unset($eContent[$key]); }else{ $eContent[$key][0] = str_replace("\n",'',trim($eContent[$key][0]," \t\n\r\0\x0B")); $eContent[$key][0] = str_replace("\t",'',trim($eContent[$key][0]," \t\n\r\0\x0B")); $eContent[$key][0] = str_replace("\r",'',trim($eContent[$key][0]," \t\n\r\0\x0B")); $eContent[$key][0] = str_replace(" ",'',trim($eContent[$key][0]," \t\n\r\0\x0B")); $eContent[$key][1] = str_replace("\n",'',trim($eContent[$key][1]," \t\n\r\0\x0B")); $eContent[$key][1] = str_replace("\t",'',trim($eContent[$key][1]," \t\n\r\0\x0B")); $eContent[$key][1] = str_replace("\r",'',trim($eContent[$key][1]," \t\n\r\0\x0B")); $eContent[$key][1] = str_replace(" ",'',trim($eContent[$key][1]," \t\n\r\0\x0B")); } } $i = 1; $out = $outFile = ''; $iStop = count($eContent); foreach ($eContent as $key => $value) { $outFile .= $eContent[$key][0].'{'.$eContent[$key][1].'}'; if($i !== $iStop){ $outFile .= "\n"; } $i++; } file_put_contents($fileCompressed, $outFile);