| Compress HTML |
Compressing your HTML page using PHP
Compressing a HTML page in php in very simple to implement especially if you use a content management system for your website.
PHP CODE:
- // Start output buffer.
- // html code
- ?>
- // function to compress page.
- function compress_page($buffer) {
- // remove comments, tabs, spaces, newlines, etc.
- "/ +/" => " ",
- "/|[\t\r\n]||\/\/ ||\]\]>|\/\/\]\]>|\/\/ => ""
- );
- return $buffer;
- }
- // turn off output buffering and output the page.
- ?>
And that's it at it's very basic!
This function will not compress commented JavaScript, it will compress the JavaScript that's not commented. For JavaScript compression it is best to serve the JavaScript from external files and compressed with either JavaScriptPacker.php or YUI compressor. CSS compression can be further done with another compression function and I will show this in another tutorial.
Main Menu
Contacts
If you would like to contact me regarding the range of serves that I can offer. Please use the details below.
Office: 01767 631679
email: Shaun Freeman
Ubuntu
Donate
Links
Site Specs
Site best viewed in a screen resolution of 1024x768 & 32 bit colours or higher using the latest version of Firefox
