How can PHP be used to extract the last modified date of a page?
To extract the last modified date of a page using PHP, you can use the `filemtime()` function to get the timestamp when the file was last modified. You can then use the `date()` function to format this timestamp into a human-readable date format.
$filename = 'path/to/your/file.html';
if (file_exists($filename)) {
$lastModified = filemtime($filename);
$formattedDate = date("F d Y H:i:s.", $lastModified);
echo "Last modified date: " . $formattedDate;
} else {
echo "File does not exist.";
}
Keywords
Related Questions
- What are the best practices for handling nested objects when converting them to arrays in PHP?
- Are there any alternative functions or methods to wordwrap in PHP that may better suit specific needs?
- What potential issues may arise when multiple scripts simultaneously open and write to the same log file in PHP?