Jump to content

Hour/Minute Question


Recommended Posts

Here's a piece of the script I'm using:


$new_file = $dir.date('l-H-i').'.php';


The entire script pulls and displays different php files at different times of the day. The files are named something like "Monday-09-30" and so on. Here's my question. If I have certain hours without any minutes (for instance, Monday-07), will it automatically display that file during the entire 7th hour?


I hope this makes sense.

Link to comment
Share on other sites

Your best bet is to test it -- try creating test file using today's information but without the hour, and seeing what occurs.


My guess, however, is that it won't work. You are specifying a specific file name, and it isn't going to be smart enough to determine what to do if that file doesn't exist. If you want it to work that way, you'll need to code it to check if the initial file 404s (probably using http://php.net/manual/en/function.file-exists.php) and if it doesn't, then try a variation without the hour information. If that file then 404s, you'll need to set it up so it displays some default content.

Link to comment
Share on other sites

No, it's not smart enough. I came up with this:


$dir = 'mydirectory/';
$new_file = $dir.date('l-H-i').'.php';
if(file_exists($new_file)) { 
 include $new_file;
else { 
 $files = glob($dir.'Friday-00.php');
 include $files[rand(0, count($files)-1)];


"Friday-00" is a sort of default file that can be used during any undesignated time. This script was originally written to use a random file if no file matched the time. I just changed the file name from "*" to "Friday-00". It works for my purpose. Just thought I would share in case someone else was looking for something similar.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...