更精確地說,getlastmod() 會回傳呼叫它的腳本上次被修改的時間,它不需要也不使用任何參數。
(PHP 4, PHP 5, PHP 7, PHP 8)
getlastmod — 取得頁面最後修改時間
此函式沒有參數。
範例 #1 getlastmod() 範例
<?php
// 輸出例如 'Last modified: March 04 1998 20:43:59.'
echo "上次修改時間: " . date ("F d Y H:i:s.", getlastmod());
?>
回傳所有 include 檔案中最新的修改時間
<?php
function get_page_mod_time() {
$incls = get_included_files();
$incls = array_filter($incls, "is_file");
$mod_times = array_map('filemtime', $incls);
$mod_time = max($mod_times);
return $mod_time;
}
?>
如果您在某些 SAPI 上使用 register_shutdown_function(),則 shutdown 函式內的各種檔案系統相關操作可能會產生非預期的結果,其中之一就是此函式可能會回傳 false。
另一方面,getlastmod() 顯然會快取回傳值,所以如果您在一般程式碼中至少使用它一次,它應該在剩餘的請求中都能正常運作。