PHP Classes

File: examples/html/example.php

Recommend this page to a friend!
  Classes of Christian Vigh   PHP Minify JS, CSS, PHP and HTML   examples/html/example.php   Download  
File: examples/html/example.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Minify JS, CSS, PHP and HTML
Reduce the size of source files in PHP, CSS or JS
Author: By
Last change:
Date: 7 years ago
Size: 955 bytes
 

Contents

Class file image Download
<?php
   
// This example minifies file "example.html" and displays its minified contents
    // The original contents of the file are displayed only when working in non-cli mode
   
require ( "../../HtmlMinifier.phpclass" ) ;

   
$input = "example.html" ;

   
$webmode = ( php_sapi_name ( ) != 'cli' ) ;

    if (
$webmode )
       {
        echo
"<h1>Contents of original file :</h1><pre>" ;
       
$contents = htmlspecialchars ( file_get_contents ( $input ) ) ;
        echo
"$contents</pre><br/><br/>" ;
        echo
"<h1>Contents of minified file :</h1><pre>" ;
        }

   
$minifier = new HtmlMinifier ( ) ;
   
$minified_contents = $minifier -> MinifyFrom ( $input ) ;
    echo
$minified_contents ;

    if (
$webmode )
        echo
"</pre><br/><br/><h1>Size comparison :</h1><pre>" ;
    else
        echo
"\n\nSize comparison :\n" ;

    echo
"\tSource file : " . filesize ( $input ) . " bytes\n" ;
    echo
"\tMinified file : " . strlen ( $minified_contents ) . " bytes\n" ;