A while back I found a script for displaying different images based on the date…problem being that a few weeks ago I had a problem with one of my hard drives and lost a load of files, and I fear this script was one of the ones amongst them, as I can’t find it anywhere. I can’t remember where I originally found the script though. I’ve looked all over online and can’t find it again. I thought maybe it was here, but after searching around I can’t find it - I’ve asked and checked in various places, but haven’t been able to find it again.
The script allowed you to displaying an image based on the date, and would allow you to display different images on specific dates, or between selected dates, and display a default date if the current date wasn’t one listed with a specific image to display. It specified just the date and month so that it’s not year specific and is reuseable.
On another forum I got this, which is the closest to what I remember of the original script:
switch(date('m-d')) {
// multiple dates with same image
case '02-15':
case '02-07':
print '<img src="/path/to/image.jpg" alt="" />';
break;
// really long ranges don't work all that well in this solution
case '03-01':
case '03-02':
case '03-03':
case '03-04':
case '03-05':
case '03-06':
case '03-07':
case '03-08':
case '03-09':
case '03-10':
print '<img src="/path/to/image.jpg" alt="" />';
break;
// specific date image
case '12-25':
print '<img src="/path/to/christmas.jpg" alt="" />';
break;
// fallback image
default:
print '<img src="/path/to/default.jpg" alt="" />';
break;
}
The problem is (and I can’t remember how it was done in the original script) is that I can’t work out how to specify that an image should be displayed between to dates doing it with switch/case. I remember the original script was very much like the one above, except that the case statement was something along the lines of:
case '03-01' ?????????? 04-05':
(obviously the ‘???’ represents the bit I can’t remember). I’ve tried:
('01-25','01-31'):
…but it doesn’t like that at all, and:
case ('01-25'>='01-31'):
…which worked for the first date, and I thought I’d got it working, but then didn’t work for any subsequent dates or date ranges. I particularly liked the switch/case method because it seemed quite compact, and less code than using if/else/elseif, as I’ve quite a few individual dates and date ranges to list - as the dates are cancer awareness months, days, and other events run by medical charities, and there’s quite a few of them!
Has anyone any idea how I can specify a date range using this sort of format?