find the last modified date of a json file in php

To find the last modified date of a JSON file in PHP you can use the filemtime function, which returns the last modified time of a file in Unix timestamp format. Here's an example code block:

main.php
$file = 'example.json';
if(file_exists($file)) {
  $lastModified = filemtime($file);
  echo 'Last modified date: ' . date("Y-m-d H:i:s", $lastModified);
} else {
  echo 'File not found.';
}
190 chars
8 lines

In this example, we first check if the file exists using the file_exists function, and then use the filemtime function to get the last modified time of the file. We then convert the Unix timestamp to a readable date format using the date function. If the file does not exist, we output an error message.

related categories

gistlibby LogSnag