This tutorial will show you how to display the date/time that the file was last modified.
Here you go, I commented each line, if you have a question don't hesitate to ask.
<?php // The file to that will read. $file = 'thefile.php'; // The variable that holds the function to display the date modified info. $last_time_modified = filemtime($file); // Format that time and date into a human readable format $last_mod = "Page last edited " . date("m/j/y h:i", $last_time_modified); // print the new formatted string and display the last modified info. //You could also pass the "$last_mod" variable to another piece of your script print $last_mod; ?>
That is the end of the tutorial. I hope you have an understanding of how "filemtime" works.
Mark Fri Mar 13, 2009 12:46 am
Thanks for your tutorial above. I found it very useful.
I made a modification so that you don't need to specify a filename:
// $n for a newline
$n = "
$path = $_SERVER['PHP_SELF'];
$file = basename($path);
$last_time_modified = filemtime($file);
// use the format you would like the date outputted as, i.e. jS M y
$last_mod = "Last updated: " . date("jS M y - H:i:s T", $last_time_modified) . $n;
Use the $_SERVER[''] if Global variables are not enabled on the server.
Mark Thu Apr 2, 2009 10:04 am
N.B. My earlier comment with php code should have included the following:
1. Starting php tag 2. The new line variable $n =" < br >"; (without the spaces!)
Validate Site: XHTML CSS | Designed by: Matthew Keefe of mkeefeDESIGN