3 namespace PhpXmlRpc\Helper;
8 * decode a string that is encoded w/ "chunked" transfer encoding
9 * as defined in rfc2068 par. 19.4.6
10 * code shamelessly stolen from nusoap library by Dietrich Ayala.
12 * @param string $buffer the string to be decoded
16 public static function decode_chunked($buffer)
22 // read chunk-size, chunk-extension (if any) and crlf
23 // get the position of the linebreak
24 $chunkend = strpos($buffer, "\r\n") + 2;
25 $temp = substr($buffer, 0, $chunkend);
26 $chunk_size = hexdec(trim($temp));
27 $chunkstart = $chunkend;
28 while ($chunk_size > 0) {
29 $chunkend = strpos($buffer, "\r\n", $chunkstart + $chunk_size);
31 // just in case we got a broken connection
32 if ($chunkend == false) {
33 $chunk = substr($buffer, $chunkstart);
34 // append chunk-data to entity-body
36 $length += strlen($chunk);
40 // read chunk-data and crlf
41 $chunk = substr($buffer, $chunkstart, $chunkend - $chunkstart);
42 // append chunk-data to entity-body
44 // length := length + chunk-size
45 $length += strlen($chunk);
46 // read chunk-size and crlf
47 $chunkstart = $chunkend + 2;
49 $chunkend = strpos($buffer, "\r\n", $chunkstart) + 2;
50 if ($chunkend == false) {
51 break; //just in case we got a broken connection
53 $temp = substr($buffer, $chunkstart, $chunkend - $chunkstart);
54 $chunk_size = hexdec(trim($temp));
55 $chunkstart = $chunkend;