I'm using some regex (that works), but don't actually understand what it's doing. Being a scientist, I like to follow everything that I do!
The code is from this SO answer: https://stackoverflow.com/a/118886/889604
$mtime = filemtime($_SERVER['DOCUMENT_ROOT'] . $file);
return preg_replace('{\\.([^./]+)$}', ".$mtime.\$1", $file);
This code takes a file name (e.g. /files/style.css
), and adds in the file's mtime
(e.g. /files/styles.1256788634.css
).
So, I get that ^
and $
symbols are the beginning and end of the string to match, and that the ./
matches any character any number of times (because of the +
), but how does the mtime
end up inbetween the file name and the extension?