note 71849 added to function.fsockopen
| From: | jkatricochetsolutionsdotcom at osu1 dot php dot net | Date: | Tue, 19 Dec 2006 15:20:37 +0000 |
| Subject: | note 71849 added to function.fsockopen | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-120770@lists.php.net to get a copy of this message | ||
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
----
Server IP: 66.163.161.117
Probable Submitter: 209.204.83.5
----
Manual Page -- http://www.php.net/manual/en/function.fsockopen.php
Edit -- https://master.php.net/note/edit/71849
Del: integrated -- https://master.php.net/note/delete/71849/integrated
Del: useless -- https://master.php.net/note/delete/71849/useless
Del: bad code -- https://master.php.net/note/delete/71849/bad+code
Del: spam -- https://master.php.net/note/delete/71849/spam
Del: non-english -- https://master.php.net/note/delete/71849/non-english
Del: in docs -- https://master.php.net/note/delete/71849/in+docs
Del: other reasons-- https://master.php.net/note/delete/71849
Reject -- https://master.php.net/note/reject/71849
Search -- https://master.php.net/manage/user-notes.php