The right way to do this is to use
curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'curlHeaderCallback');
The callback will take two parameters - first CURL Handle, the second - the header. It will be called every time a new header arrives.
$acceptable=array('application/xhtml+xml', 'application/xml', 'text/plain', 'text/xml', 'text/html'); function curlHeaderCallback($resURL, $strHeader) { global $acceptable; if (stripos($strHeader,'content-type')===0) { $type=strtolower(trim(array_shift(explode(';',array_pop(explode(':',$strHeader)))))); if (!in_array($type,$acceptable)) return 0; } return strlen($strHeader);
}
source share