PHP Classes

File: compactor.example1.php

Recommend this page to a friend!
  Classes of Oliver Lillie  >  HTML Compactor  >  compactor.example1.php  >  Download  
File: compactor.example1.php
Role: Example script
Content type: text/plain
Description: Example File 1
Class: HTML Compactor
Reduce HTML document size by removing white-spaces
Author: By
Last change: added demo size test
Date: 13 years ago
Size: 552 bytes
 

Contents

Class file image Download
<?php

   
require_once 'compactor.php';

   
$html = file_get_contents('http://www.bbc.co.uk');

   
$size_before = mb_strlen($html, '8bit');
   
   
$compactor = new Compactor(array(
       
'buffer_echo' => false
   
));
   
$html = $compactor->squeeze($html);
   
   
$size_after = mb_strlen($html, '8bit');
   
    echo
'With whitespace removed the size of the HTML file has been shrunk from '.round($size_before/1024, 2).'KB to '.round($size_after/1024, 2).'KB saving '.round((1-($size_after/$size_before))*100, 2).'%<br />
-----------------<br />
<br />'
.$html;
   

For more information send a message to info at phpclasses dot org.