You are here

function cf_http_unchunk_response in Common Functionality 7.2

Same name and namespace in other branches
  1. 7 modules/cf_http/cf_http.module \cf_http_unchunk_response()

Unchunk http content.

Originally From: http://php.net/manual/en/function.fsockopen.php#85572

@see: cf_http_get_webpage()

Parameters

string $document: An string representing an html document.

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.

Related topics

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 201
Common Functionality - HTTP module.

Code

function cf_http_unchunk_response($document) {
  $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;
}