metanohi-misc-subsites/subsites/projects/nalgh/example.php

27 lines
782 B
PHP
Raw Normal View History

2011-08-02 19:57:57 +02:00
<?php
include('nalgh.php');
header('content-type: text/plain; charset=utf-8');
//$txt = 'The paper was nervous. After the day of destiny it had not dared to leave the printer. The printer seemed unhappy with the situation and had subsequently tried to cheer up the piece of paper. But death had taken its toll. The ink was no more.';
$fn = 'writeclearly-preface';
$f = fopen($fn, 'r');
$txt = fread($f, filesize($fn));
fclose($f);
$len = strlen($txt);
$ntxt = nalgh_compress($txt);
$nlen = strlen($ntxt);
$dtxt = nalgh_decompress($ntxt);
$dlen = strlen($dtxt);
echo $txt;
echo "\nOriginal text: $len\n\n";
echo $ntxt;
echo "\nCompressed text: $nlen\n\n";
echo $dtxt;
echo "\nDecompressed text: $dlen\n\n";
echo 'Compressed takes up '. $nlen / $len * 100 . '% of original.';
?>