├── LICENSE ├── README └── minify.php /LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | Quick and dirty PHP function to minify common parts of CSS. 2 | 3 | This code is old; it worked at the time but may not support some of the more complex syntaxes of CSS3. For that, use a proper parser and minifier. 4 | 5 | As per the [LICENSE], this code is in the public domain, and can be used/amended as you wish, without attribution. 6 | 7 | There is no intent to improve the code in the future. 8 | -------------------------------------------------------------------------------- /minify.php: -------------------------------------------------------------------------------- 1 | 27 | $css = preg_replace( '/(,|:|;|\{|}|\*\/|>) /', '$1', $css ); 28 | 29 | // Remove space before , ; { } ( ) > 30 | $css = preg_replace( '/ (,|;|\{|}|\(|\)|>)/', '$1', $css ); 31 | 32 | // Strips leading 0 on decimal values (converts 0.5px into .5px) 33 | $css = preg_replace( '/(:| )0\.([0-9]+)(%|em|ex|px|in|cm|mm|pt|pc)/i', '${1}.${2}${3}', $css ); 34 | 35 | // Strips units if value is 0 (converts 0px to 0) 36 | $css = preg_replace( '/(:| )(\.?)0(%|em|ex|px|in|cm|mm|pt|pc)/i', '${1}0', $css ); 37 | 38 | // Converts all zeros value into short-hand 39 | $css = preg_replace( '/0 0 0 0/', '0', $css ); 40 | 41 | // Shortern 6-character hex color codes to 3-character where possible 42 | $css = preg_replace( '/#([a-f0-9])\\1([a-f0-9])\\2([a-f0-9])\\3/i', '#\1\2\3', $css ); 43 | 44 | return trim( $css ); 45 | 46 | } 47 | --------------------------------------------------------------------------------