How to get the last modified time in php

青灯夜游
Release: 2023-03-17 17:36:01
Original
3870 people have browsed it

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)
Copy after login
  • $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);
?>
Copy after login

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()
Copy after login

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);
?>
Copy after login
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!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!