function cf_http_unchunk_response in Common Functionality 7
Same name and namespace in other branches
- 7.2 modules/cf_http/cf_http.module \cf_http_unchunk_response()
Unchunk http content.
Originally From: http://php.net/manual/en/function.fsockopen.php#85572
Why: Custom php scripts need a straight-forward and easy way to pull data from another website. This is useful as an alternative to iframe and has advantages and disadvantages to iframes. An advantage is that this allows showing remote content even if the remote url is down (via caching). A disadvantage is that remote images and links need to be processed, updated, and possibly even manually cached.
Parameters
string $document: An string representing an html document.
array $function_history: (optional) An array of function names, ie: array('0' => 'my_function_name').
Return value
array An array containing the unchunk status and unchunked string. The array keys:
- unchunked: A boolean with TRUE representing that the document string was
successfully unchunked, FALSE otherwise.
- document: The complete (unchunked) html document.
1 call to cf_http_unchunk_response()
- cf_http_parse_response in modules/
cf_http/ cf_http.module - Accepts and processes provided http content.
File
- modules/
cf_http/ cf_http.module, line 200
Code
function cf_http_unchunk_response(string $document, array $function_history = array()) {
$results = array(
'unchunked' => FALSE,
'document' => '',
);
if (empty($document)) {
return $results;
}
$eol = "\r\n";
$add = strlen($eol);
$tmp = $document;
do {
$tmp = ltrim($tmp);
$position = strpos($tmp, $eol);
if ($position === FALSE) {
return $results;
}
$length = hexdec(substr($tmp, 0, $position));
if (!is_numeric($length) || $length < 0) {
return $results;
}
$results['document'] .= substr($tmp, $position + $add, $length);
$tmp = substr($tmp, $length + $position + $add);
$check = trim($tmp);
} while (!empty($check));
unset($tmp);
return $results;
}