Jump to content

Recommended Posts

Posted

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.

Posted

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.

Posted

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

 

<?php
$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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...