I have several filenames in this format
I would like to define $year as the last 4 characters of the file itself, so inside the file, for example in the body of test_2018.php I have the following code:
Code: Select all
$path = getenv('SCRIPT_NAME'); $filename = basename($path, ".php"); $imagename = $filename; $year = substr($imagename, strrpos($imagename, "2"), 4);
This works with all the files ending with 2000 to 201, but not with filenames such as
How can I modify the code to read the last 4 characters of the filename no matter how long the filename is?