Categories > Your tips & tricks >

Snippet: Compress source

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: LeoC
Date: 2009-04-15
Time: 20:40

Snippet: Compress source

I´ve found this function and put it as a TBS method
to compress source (with Render false) and put
all output in a single line html.

I hope it can be useful to someone.

function compressBuffer($b)
{
    $b = str_replace(array("\r\n", "\r", "\n", "\t"), ' ', $b);
    $b = ereg_replace(" {2,}", ' ',$b);
    $b = str_replace("> <", "><", $b);
    $b = str_replace(" &nbsp;", "&nbsp;", $b);
    $b = str_replace("&nbsp; ", "&nbsp;", $b);
    return $b;
}

Cheers.
By: RwD
Date: 2009-06-18
Time: 08:38

Re: Snippet: Compress source

Does that speed up processing? Als, changing > < into >< changes the source. Isn't str_replace faster if you use arrays as input and replace?

Did you time this on anything?
By: LeoC
Date: 2009-06-23
Time: 00:29

Re: Snippet: Compress source

Yes. I did...

(Its so old and LAME that im ashamed. :|)

Working on a Gzip compression plugin now. Much better btw. :)

Thanks for your attention.