-
date modified [Resolved]
I'm trying to put the date a file was modified on each page that I have but I want to put that in an included file (footer.php) and I'm using the following code:
PHP Code:
$modified = stat();
echo " " . date("l, F dS",$modified[9]);
Where the name of the file you're getting the stats on is the name of the current page you're on.
The problem is, all server variables that are available also contain the path to that file. How do I remove the folder/path name from the $_SERVER['SCRIPT_NAME'] call?
Or is there a better way to do this?
-
Got it:
PHP Code:
$tok = strtok($_SERVER['SCRIPT_NAME'], "/");
$sname = "";
while ($tok) {
if(trim($tok) != "")
$sname = $tok;
$tok = strtok("/");
}
$modified = stat($sname);
echo "<br>Procedure Modified: " . date("n/j/Y",$modified[9]);
-
Found this have a look
PHP Code:
<?php
// outputs e.g. somefile.txt was last modified: December 29 2002 22:16:23.
$filename = 'somefile.txt';
if (file_exists($filename)) {
echo "$filename was last modified: " . date ("F d Y H:i:s.", filemtime($filename));
}
?>
http://uk.php.net/manual/en/function.filemtime.php
-
Thanks :)
New code:
PHP Code:
$tok = strtok($_SERVER['SCRIPT_NAME'], "/");
while ($tok) {
if(trim($tok) != "")
$sname = $tok;
$tok = strtok("/");
}
echo "<br>Procedure Modified: " . date("n/j/Y",filemtime($sname));
-
Why loop when you don't have to?
PHP Code:
$sname = substr($_SERVER['SCRIPT_NAME'], strrpos($_SERVER['SCRIPT_NAME'], '/') + 1);
echo "<br>Procedure Modified: " . date("n/j/Y",filemtime($sname));
:)
-
ah ha... see... that's the solution I was looking for :D
Thanks