Forum Moderators: coopster

Message Too Old, No Replies

stripping newlines and tabs from html output

worth it?

         

tkroll

2:20 am on May 16, 2005 (gmt 0)

10+ Year Member



Does it make sense to strip newlines, tabs, extra spaces, etc. from a scripts' output? It should reduce the page size a bit and obfuscate the HTML.

What would be the best way to do this?

Thanks!

Stormfx

5:24 am on May 16, 2005 (gmt 0)

10+ Year Member



You can do this, I suppose. Just remember that certain things do require spaces. For example, to assign multiple CSS classes to an HTML element, the class names have to be seperated by a space. But you can use str_replace to do what you need.

tkroll

5:32 am on May 16, 2005 (gmt 0)

10+ Year Member



Yes, of course you are correct. I meant to say replace multiple space sequences with a single space.

The only way is to use output buffering, right?

Stormfx

6:02 pm on May 16, 2005 (gmt 0)

10+ Year Member



Yeah, if your output is spit out at different times, ob is the way to go.
<?php

// start
if (ob_get_levels() == 0) {
ob_start();
}

// code...

// end
$content = ob_get_contents();
ob_end_clean();

// use str_replace to do what you need

echo $content;

tkroll

1:08 am on May 17, 2005 (gmt 0)

10+ Year Member



Cool! That is what I thought. There is no way to do it without output buffering?