Possible Duplicate:
Decompressing a .gz file via PHP
I cannot use gzdecode with php as it is not installed and I cannot install it,
I have been using this so far…
// GZIP DECODE
function gzDecode($d) {
$f = ord(substr($d, 3, 1));
$h = 10;
$e = 0;
if($f&4) {
$e = unpack('v', substr($d, 10, 2));
$e = $e[1];
$h += 2 + $e;
}
if($f&8) {
// ERROR HERE
$h = @strpos($d, chr(0), $h) + 1;
}
if($f&16) {
$h = strpos($d, chr(0), $h) + 1;
}
if($f&2) {
$h += 2;
}
// ERROR HERE
$u = @gzinflate(substr($d, $h));
if($u == false) {
$u = $d;
}
return $u;
}
It works but is there a better solution for PHP 5.3? If not is there any way I can get rid of the errors that are present?
Have you had a look at some of the materials shown in the comments of http://php.net/gzdecode? The comments include a simple way using
gzinflate()and a pure PHP implementation of thegzdecode()function you can lift entirely.As a general rule of thumb, don’t reinvent the wheel where you don’t have to!