An anonymous function in a php library is incompatible with php 5.2 -
how can convert following anonymous function, found in php library using, compatible php 5.2 (which not support anonymous functions):
curl_setopt($curl, curlopt_writefunction, function($handle, $data) use (&$headers, &$body, &$header_length, $max_data_length) { $body .= $data; if ($headers == '') { $headers_end = strpos($body, "\r\n\r\n"); if ($headers_end !== false) { $header_length = $headers_end; $headers = substr($body, 0, $header_length); $body = substr($body, $header_length + 4); # have headers, if content type not html, # not need download else. prevents downloading # images, videos, pdfs, etc. won't contain redirects # until php 5.4, can't import $this lexical variable closure, # need duplicate code contenttypefromheader() # , hashtmlcontenttype() if (preg_match('/^\s*content-type:\s*([^\s;\n]+)/im', $headers, $matches)) { if (stripos($matches[1], 'html') === false) { return 0; } } } } # if have downloaded maximum amount of content, we're done. if (($header_length + strlen($body)) > $max_data_length) { return 0; } return strlen($data); });
thank you!
you'll need convert anonymous function named function , reference in curl_setopt
call, approximately thus:
function curl_writefunction_callback($handle, $data) { global $headers; global $body; global $header_length; global $max_data_length; # [function body here] }; curl_setopt($curl, curl_writefunction, "curl_writefunction_callback");
Comments
Post a Comment