Home  >  Article  >  Backend Development  >  How to get the last modified time in php

How to get the last modified time in php

青灯夜游
青灯夜游Original
2023-01-04 19:06:173877browse

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.

How to get the last modified time in php

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:

How to get the last modified time in php

<?php
header("Content-type:text/html;charset=utf-8");
$file = "test.txt";
echo "文件修改时间为:".filemtime($file);
?>

How to get the last modified time in php

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 file

getlastmod()

Return value:

  • Returns the last modification time of the current page. This value is a Unix timestamp that can be formatted for output using the date() function; false is returned on error.

Example: Get the last modified time of the current page file

##

<?php
$time = getlastmod();
echo date(&#39;Y-m-d H:i:s&#39;,$time);
?>
How to get the last modified time in php

How to get the last modified time in php Recommended learning: "

PHP Video Tutorial

"

The 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn