How to get the last modification time: 1. Use the filemtime() function to get the last modification time of the specified file. The syntax "filemtime($filename)" will return the last modification time of the file content in the form of a Unix timestamp. ; 2. Use the getlastmod() function to obtain the last modification time of the current file. The syntax "getlastmod()" will also return the last modification time in the form of a Unix timestamp.
The operating environment of this tutorial: windows7 system, PHP8 version, DELL G3 computer
Method 1: Use filemtime( ) function gets the last modification time of the specified file
filemtime() function returns the last modification time of the file content.
filemtime($filename)
$filename
: Required. Specifies the documents to be checked.
Return value:
If successful, this function will return the last modification time of the file content in the form of a Unix timestamp. On failure, returns FALSE.
Note: The result of this function will be cached. Please use clearstatcache() to clear the cache.
Example: There is a text file named "test.txt" below, and its last modification time is as follows:
<?php header("Content-type:text/html;charset=utf-8"); $file = "test.txt"; echo "文件修改时间为:".filemtime($file); ?>
Extended knowledge: Functions to obtain creation time and last access time
filectime($filename )
: Returns the creation time of the file
fileatime($filename)
: Returns the last access time of the file
Method 2: Use the getlastmod() function to get the last modification time of the current file
##getlastmod - Get the last modification time of the current page filegetlastmod()
Example: Get the last modified time of the current page file
##
<?php $time = getlastmod(); echo date('Y-m-d H:i:s',$time); ?>
Recommended learning: "
PHP Video TutorialThe above is the detailed content of How to get the last modified time in php. For more information, please follow other related articles on the PHP Chinese website!