Articles & Code Snippets


HTML Minifier

HTML Minifier - Minify HTML and any CSS or JS included in your markup


This will do the magic:

//start HTML Minifier
function sanitize_output($html) {
    $search = array(
        '/\>[^\S ]+/s',     // strip whitespaces after tags, except space
        '/[^\S ]+\/' // Remove HTML comments
    );
    $replace = array(
        '>',
        '<',
        '\\1',
        ''
    );
    $html = preg_replace($search, $replace, $html);
    return $html;
}
ob_start("sanitize_output"); 
// end HTML Minifier

web


Archives

Just feel like saying Hi?

  1 (903) NEGRARU phone
  email