Are there any best practices for automatically generating and displaying last modification dates in PHP?

When automatically generating and displaying last modification dates in PHP, it is important to ensure that the date is updated whenever the content is modified. One way to achieve this is by using the filemtime() function to get the last modification timestamp of the file and then formatting it using the date() function.

$file = 'example.txt';
if (file_exists($file)) {
    $lastModified = date("F d Y H:i:s.", filemtime($file));
    echo "Last modified: " . $lastModified;
} else {
    echo "File does not exist.";
}