infinite
07-17-2002, 06:33 AM
Hi!
Has anyone used a tool called Absolute HTML compressor? It's a windoze program that reduces a HTML file down by 10-20%, by removing extra white space, and unecessary new lines.
I was wondering if anyone has used or developed a PHP function that achives a similar result?
Cheers,
Infinite ;)
Starhost
07-17-2002, 07:34 AM
If you ad ob_gzhandler to yout php.ini all PHP prased pages will be automatially compressed by gzip if the clients browser supports it.
; You can redirect all of the output of your scripts to a function. For
; example, if you set output_handler to "ob_gzhandler", output will be
; transparently compressed for browsers that support gzip or deflate encoding.
; Setting an output handler automatically turns on output buffering.
;output_handler =
output_handler = ob_gzhandler
infinite
07-17-2002, 07:53 AM
Originally posted by Starhost
If you ad ob_gzhandler to yout php.ini all PHP prased pages will be automatially compressed by gzip if the clients browser supports it.
Thanks for the tip Starhost ;), but gzip compression is already enabled, I'd just like to see if I can compress the HTML before gzip does, so if the browser won't support gzip, it will still be slightly compressed :D
Also, I guess gzip would compress a HTML page more, that's been compressed/optimised already?
Cheers,
Infinite :)
esdjco
07-18-2002, 12:51 AM
Hmm thats interesting...Id like to know if anyone has used this tool as well.
infinite
07-18-2002, 12:47 PM
This is what I've got so far, it removes line returns, and multiple white space.
Would anyone know how to remove HTML comment tags? :D
<?php
function callback($buffer) {
// Strip newlines and extra white space,
// not yet sensitive to textarea tags
$search = array ("'([\r\n])+'", // Strip out newlines
"'[\s][\s]'"); // Strip out multiple white spaces
$replace = array ("",
"",
"");
return ( preg_replace ($search, $replace, $buffer) );
}
ob_start("callback");
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body>
Test page
<BR>
<BR>
ho ho ho !</body>
</html>
<?php
ob_end_flush();
?>
I've had a go at removing <!-- --> tags, but with no result so far, any help is much appreciated ;)
The above code brings my homepage down by 3%, not much, but the results will be much better on larger pages :D
TIA,
Infinite :)
infinite
07-18-2002, 12:55 PM
Originally posted by esdjco
Hmm thats interesting...Id like to know if anyone has used this tool as well.
The tool actually does more than I want, this is what is listed in the help file
Merge lines.
Remove unnecessary whitespace characters.
Remove unnecessary quotation marks. For example, <table BORDER="0" CELLSPACING="0" CELLPADDING="0" align="center"> will be converted to <table BORDER=0 CELLSPACING=0 CELLPADDING=0 align=center>.
Replace some tags with the short ones - replace STRIKE tags with S, STRONG with B and EM with I.
Remove HTML comments. The comments within the scripts and styles aren't removed.
Remove <!DOCTYPE ...> tags.
Remove meta tags. You can specify names of the meta tags to remove.
Create backups. If this option is ON backups of the optimized files are created in a new folder.
But I don't want to remove all of these, just line returns and white space (and HTML comments) ;)
Cheers,
Infinite :)