PHP Classes

File: usage_example.php

Recommend this page to a friend!
  Classes of João Romão   CssShrink   usage_example.php   Download  
File: usage_example.php
Role: Example script
Content type: text/plain
Description: CssShrink usage samples
Class: CssShrink
Compress CSS files by removing unneeded characters
Author: By
Last change:
Date: 15 years ago
Size: 2,695 bytes
 

Contents

Class file image Download
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US">
 <head>
  <title>CssShrink v1.0 - CSS Compressor &amp; Uncompressor</title>
  <meta http-equiv="Author" content="Jo&atilde;o Rom&atilde;o - iceburn.info" />
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <style type="text/css">
    html { background-color: #4B4B4B; }
    body { color: #FF7F00; background-color: #4B4B4B; margin-bottom: 40px; font-family: Georgia, serif; }
    a, a:link, a:active, a:visited { color: #FF7F00; text-decoration: underline; }
    a:hover { color: #FF7F00; text-decoration: none; }
    legend { font-size: 22px; color: #00D4FF; font-weight: bold; padding: 0 4px; font-style: italic; }
    fieldset { margin-top: 40px; max-height: 360px; border: 4px solid #000; }
    fieldset pre {
        display: block; font-family: 'Courier New', Courier, monospace; padding: 10px; max-height: 300px;
        overflow: auto; width: auto; white-space: pre; background-color: #5A5A5A; color: #FFD500;
    }
  </style>
 </head>
<body>

<h1>CssShrink v1.0 - CSS Compressor &amp; Uncompressor</h1>
<h2>Demonstration</h2>

<?php

// Include our class
require_once('./CssShrink.class.php');

// Initiate
$css = new CssShrink();

// Input your CSS style sheet:
$css->css = file_get_contents('./style.css');

echo
'<fieldset>';
echo
'<legend> Original CSS </legend>';
echo
'<pre>',htmlspecialchars( $css->css ),'</pre>';
echo
'</fieldset>';

// Compress it:
$comp = $css->compressed();

// Echo it to the browser:
echo '<fieldset>';
echo
'<legend> Compressed CSS </legend>';
echo
'<pre>',htmlspecialchars( $comp ),'</pre>';
// Verify the compressed gain over the input (the result is based on the chars diference)
echo '<p><em>GAIN: <strong>', $css->gain(), '</strong></em></p>';
echo
'</fieldset>';

// Optionally dump the compressed version to a file.
//$css->dump2file('./new_style.css', $comp);

// Uncompress (this works based on the css input)
// In this case will only cleans up the original file...
echo '<fieldset>';
echo
'<legend> Original Uncompressed and cleaned CSS </legend>';
echo
'<pre>',htmlspecialchars( $css->uncompressed() ), '</pre>';
echo
'</fieldset>';

// ...but can be called to uncompress a previously compressed CSS
echo '<fieldset>';
echo
'<legend> Previous Compressed CSS Reverted (Uncompress operation)</legend>';
echo
'<pre>',htmlspecialchars( $css->uncompressed($comp) ), '</pre>';
echo
'</fieldset>';

?>

 <p><small><a href="http://iceburn.info">iceburn.info</a> &copy; 2008</small></p>
 
 </body>
</html>