Zend - The PHP Company




HTML

Add Code


livecruncher v1.0  

Type: application
Added by: cocotime
Entered: 16/02/2001
Last modified: 02/12/2000
Rating: - (fewer than 3 votes)
Views: 5880
html-code is compressed by php4 and recompressed by javascript advantage: up to 25% less traffic, thus more speed, less costs files can also be stored in the crunched version recrunch - javascript is very fast. how it works: html is splitted by "


<?
#(c)2001 by Herwig Seitz office@cocotime.com
# for commercial usage pls contact me at office@cocotime.com
#name: livecruncher v1.0
#function: html-code is compressed by php4 and recompressed by javascript
#advantage: up to 25% less traffic, thus more speed, less costs
#files can also be stored in the crunched version
#recrunch - javascript is very fast.
#how it works:
# html is splitted by "<" and stored in an array (unique).
# then html is parsed. each word is replaced by it's index.
# if you crunch only text, crunchfactor will be only 1%, the more text the better.
# html works pretty good.
#This is freeware. If you use this script pls DO mention my copyright!

#######################################################################################################
$source="<table border=1>
<tr><td>a</td><td>b</td><td>This</td><td>x</td><td>x</td></tr>
<tr><td>b</td><td>c</td><td>is</td><td>x</td><td>x</td></tr>
<tr><td>c</td><td>d</td><td><b>a</b></td><td>x</td><td>x</td></tr>
<tr><td>d</td><td>e</td><td>test</td><td>x</td><td>x</td></tr>
<tr><td>e</td><td>f</td><td>for</td><td>x</td><td>x</td></tr>
<tr><td>f</td><td>g</td><td><b>livecruncher v1.0</b></td><td>x</td><td>x</td></tr>
<tr><td>g</td><td>h</td><td>(c)2001 by Herwig Seitz</td><td>x</td><td>x</td></tr>
<tr><td>a</td><td>i</td><td>This is freeware. If you use this script pls DO mention my copyright!</td><td>x</td><td>x</td></tr>
</table>
"
;
# or read file into $source
#######################################################################################################

# code: do NOT change unless you know what you are doing :-)
$tz="<";
$target=str_replace("r","",$source);
$target=str_replace("t","",$target);
$target=str_replace("n","",$target);
$target=str_replace("'","'",$target);
$words=explode($tz,$target);
$unique array_unique ($words);
foreach(
$unique as $u){$t.="$tz$u";}
$wi=0;$ui=0;$x="";
foreach(
$words as $w){$ui=0;foreach($unique as $u){if($w==$u){$x.=",$ui";break;}$ui++;}$wi++;}
$target="<script>";
$target.="v='".substr($t,1)."';";
$target.="w=v.split('$tz');";
$target.="x=[".substr($x,1)."];";
$target.="i=0;";
$target.="while(i<x.length){";
$target.="document.write(w[x[i++]]+'$tz');";
$target.="}";
$target.="document.write('!-- -->');";
$target.="</script>";
echo 
$target;

#######################################################################################################
# below is only for checking crunchfactor. must be deleted if used.
$len0=strlen($source);
$len1=strlen($target);
echo 
"<hr>source: $len0<br>target: $len1<br>";
echo 
"-".(100*(1-$len1/$len0))." % crunched";
?>




Usage Example




Rate This Script





Search



This Category All Categories