note 71849 deleted from function.fsockopen by danbrown

From: Date: Mon, 18 May 2009 01:49:30 +0000
Subject: note 71849 deleted from function.fsockopen by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-155601@lists.php.net to get a copy of this message
Note Submitter: jk at ricochetsolutions dot com ---- here is my contribution for parsing chunked data. please note: this function simply handles the RESPONSE, not the HEADERS, it would be your job to check the headers for 'Transfer-Encoding: chunked' field: <?php function parseChunked($response) { $do = true; $return = ""; $size = NULL; while($do) { // suppress warnings w/ @ if offset not in string (past end) $pos = @strpos($response, "\r\n", 0); if(!($pos === false) && $size === NULL) { // we found CRLF, get len from hex $size = hexdec(substr($response, 0, $pos)); // get the actual chunk-len, reset $response, $size $return .= substr($response, $pos+2, $size); $response = substr($response, ($pos+2) + $size); $size = NULL; } else { $do = false; } // end if/else } // end while return $return; } // end function parseChunked() ?> Any recomendations or improvements please post

« previous php.notes (#155601) next »