Decode a "chunked" transfer-encoded body and return the decoded text
string $body:
string
public static function decodeChunkedBody($body) {
$decBody = '';
while (trim($body)) {
if (preg_match("/^([\\da-fA-F]+)[^\r\n]*\r\n/sm", $body, $m)) {
$length = hexdec(trim($m[1]));
$cut = strlen($m[0]);
$decBody .= substr($body, $cut, $length);
$body = substr($body, $cut + $length + 2);
}
else {
throw new EasyRdf_Exception("Failed to decode chunked body in HTTP response.");
}
}
return $decBody;
}