I’ve a webpage, which is currently completely build with PHP. Now, it would be great if it works on my local machine outside the web server, too. I figured out, that most of the stuff is just client side operations. I can easily rewrite them using Javascript. However, at one point, I am reading Date information from files stored on the server as follows (PHP):
function getFileDate($file) {
$time = filemtime($file);
$date = date('d.m.y', $time);
return $date;
}
Is it possible to integrate that call into Javascript? And, can I implement some kind of switch, so that it will only be executed on my local machine (maybe replaced by a dummy date)?
Thanks for your help!
It’s important to know that Javascript is executed by the client, PHP is executed by whatever is serving your page.
With that being said, you can easily use PHP to “echo” or otherwise “inject” values into the middle of blocks in your HTML page.
A “quick and dirty” example –
Results in the final page source becoming –