Created
April 2, 2018 16:47
-
-
Save rajuahmmed/4b09476dc0aea49e632598517d6288d7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function minify_css($css_code) | |
{ | |
// Remove comments | |
$css_code = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $css_code); | |
// Remove space after colons | |
$css_code = str_replace(': ', ':', $css_code); | |
// Remove whitespace | |
$css_code = str_replace(array("\r\n", "\r", "\n", "\t", ' ', ' ', ' '), '', $css_code); | |
// Remove Empty Selectors without any properties | |
$css_code = preg_replace('/(?:[^\r\n,{}]+)(?:,(?=[^}]*{)|\s*{[\s]*})/', '', $css_code); | |
return $css_code; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment