note 93437 deleted from function.gzinflate by danbrown
| From: | danbrown@php.net | Date: | Thu, 10 Sep 2009 00:14:18 +0000 |
| Subject: | note 93437 deleted from function.gzinflate by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-160386@lists.php.net to get a copy of this message | ||
Note Submitter: vitall at ua dot fm
----
The correct function for gzip and chunked data particularly when you get "Content-Encoding:
gzip" and "Transfer-Encoding: chunked" headers:
<?php
function decode_gzip($h,$d,$rn="\r\n"){
if (isset($h['Transfer-Encoding'])){
$lrn = strlen($rn);
$str = '';
$ofs=0;
do{
$p = strpos($d,$rn,$ofs);
$len = hexdec(substr($d,$ofs,$p-$ofs));
$str .= substr($d,$p+$lrn,$len);
$ofs = $p+$lrn*2+$len;
}while ($d[$ofs]!=='0');
$d=$str;
}
if (isset($h['Content-Encoding'])) $d = gzinflate(substr($d,10));
return $d;
}
?>
Enjoy!