我正在使用get_headers()並且我想返回內容長度。在下面的數組中,內容長度是鍵數9,但是我發現內容長度並不總是鍵數9.我不確定它爲什麼不總是相同的鍵?如何搜索數組並始終返回內容長度,無論它是什麼密鑰?正如我在一個函數中使用這個,所以每次文件的實際文件大小都是不同的。我的示例代碼如下。提前致謝。檢查數組中的鍵php
Array ([0] => HTTP/1.0 200 OK [1] => Server: Apache [2] => Pragma: public [3] => Last-Modified: Sun, 01 Apr 2012 07:59:46 GMT [4] => ETag: "1333267186000" [5] => Content-Type: text/javascript [6] => Cache-Control: must-revalidate, max-age=0, post-check=0, pre-check=0 [7] => Expires: Sun, 01 Apr 2012 10:27:26 GMT [8] => Date: Sun, 01 Apr 2012 10:27:26 GMT [9] => Content-Length: 31650 [10] => Connection: close [11] => Set-Cookie: JSESSIONID=M0V4NTTVSIB4WCRHAWVSFGYKE2C0UIV0; path=/ [12] => Set-Cookie: DYN_USER_ID=2059637079; path=/ [13] => Set-Cookie: DYN_USER_CONFIRM=6c6a03988da3de6d704ce37a889b1ec8; path=/ [14] => Set-Cookie: BIGipServerdiy_pool=637871882.20480.0000; path=/)
function headInfo($url) {
$header = get_headers($url);
$fileSize = $header[9];
return array($header, $fileSize);
}
現貨,使其$頭= get_headers($網址,1),你回來的關聯數組。然後你可以查看關鍵值。 – 2012-04-01 10:43:39