Jump to content

Minify html output


piuozorio

Recommended Posts

Hello all,

i'm trying to minify the html output but no success, i use phpvms v2.

example:

<!DOCTYPE HTML>
<html lang="pt-PT">
<head>
<meta charset="utf-8">
...

 

to be

<!DOCTYPE HTML><html lang="pt-PT"><head><meta charset="utf-8">...

 

I´m trying to use this code on top of layout.tpl

function sanitize_output($buffer) {

    $search = array(
        '/\>[^\S ]+/s',     // strip whitespaces after tags, except space
        '/[^\S ]+\</s',     // strip whitespaces before tags, except space
        '/(\s)+/s',         // shorten multiple whitespace sequences
        '/<!--(.|\s)*?-->/' // Remove HTML comments
    );

    $replace = array(
        '>',
        '<',
        '\\1',
        ''
    );

    $buffer = preg_replace($search, $replace, $buffer);

    return $buffer;
}

ob_start("sanitize_output");

when i see the source code nothing change, someone know how to do it?

Thank you

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...