Ở đây tôi nhận được các tiêu đề HTTP tài nguyên sau đó tôi phân tích các tiêu đề ra một mảng $ retval. Tôi đã nhận được mã để phân tích các tiêu đề từ đây [//www.bhootnath.in/blog/2010/10/parse-http mounders-in-php/] Bạn cũng có thể sử dụng //php.net/ Hướng dẫn sử dụng/en/function.http-parse-meaders.php Nếu bạn có [PECL PECL_HTTP> = 0.10.0]
$ch = curl_init[];
$timeout = 0;
curl_setopt [$ch, CURLOPT_URL, $url];
curl_setopt [$ch, CURLOPT_CONNECTTIMEOUT, $timeout];
curl_setopt[$ch, CURLOPT_HEADER, TRUE];
curl_setopt[$ch, CURLOPT_RETURNTRANSFER, 1];
curl_setopt[$ch, CURLOPT_BINARYTRANSFER, 1];
// Getting binary data
$header = curl_exec[$ch];
$retVal = array[];
$fields = explode["\r\n", preg_replace['/\x0D\x0A[\x09\x20]+/', ' ', $header]];
foreach[ $fields as $field ] {
if[ preg_match['/[[^:]+]: [.+]/m', $field, $match] ] {
$match[1] = preg_replace['/[?