Compress HTML Using PHP

Compress HTML Using PHP

Compress HTML Using PHP

Today i will share with you php code to compress html code.

This php code works on load as page is loaded this code runs automatically before page loading.

This code simply remove all white spaces and all blank lines and saves memory as well as compressing php code also decreases page load time.

So here is the php functions and files that you will need for this project you can copy the code or simple download archive from the download link below which contains all the files used in this project.


function compress_code($code) 
 $search = array(
  '/>[^S ]+/s',  // remove whitespaces after tags
  '/[^S ]+</s',  // remove whitespaces before tags
  '/(\s)+/s'       // remove multiple whitespace sequences

 $replace = array('>','<','\\1');
 $code = preg_replace($search, $replace, $code);
 return $code;

<!--Below is the html code to be compressed-->
<p>Compress HTML Code Using PHP</p>


Outcome :

So here we are, We have done and our project Compress Html Code Using Php is ready now you can save all the files as provided.
And run your code on localhost server or anywhere else where php can be executed.

Download Project (Compress Html Code Using Php) File :

Compress Html Code Using
File Size 597 Bytes
Click the download button above and your download will be started in few ( 10 ) seconds. If your download does not start automatically then click Download Started Button Above to download it manually.

That's it guys if you face any difficulty while running this project you can simply write a comment below I will try to answer it as soon as possible and keep visiting this site for more this kind of tutorials.

Thank you !

No Comment

Help us improve this article by leaving your feedback below.
Add Comment