Help with PHP - displaying a daily message

May 17, 2009 at 11:12:09
Specs: Windows XP
Hello all,

I've been looking for a script that will allow me
to display either a block of text, or a picture
based upon the day of the week. I haven't had
much luck finding anything, and I was hoping
someone here has some leads.

More specifically, I have certain specials that
run on my site each day, that change
depending on the day of the week - I'd like to
be able to have the special listed using .php,
so that I don't have to change that page each

See More: Help with PHP - displaying a daily message

Report •

May 17, 2009 at 20:27:19
The date function returns a string, which you could use, I think... perhaps something like


$sales = array('Sun' => array("desc" => "some text", 
                              "img" => "images/sunday.png"),
               'Mon' => array("desc" => "Monday's item",
                              "img" => "images/monday.png")); // other days

echo $sales[date('D', time())]['desc'] . 
     "<img src='" . $sales[date('D', time())]['img'] . "'>";  


You could add whatever array elements that you need to accomplish your specific goal. You don't really need the array; you could use the function from within a switch or if/else if/else type of block.

switch(date('D', time())) {
   case 'Sun' : ... break;

Hope that helps.

My work in progress. I hate JS. :P

Report •

May 17, 2009 at 20:35:29
This is a great starting point for me - thank you!

Report •

May 17, 2009 at 20:46:33
No worries. :)

One thing that I just noticed - you might want to store the date in a var rather than call it like I had it. If a visitor happens to visit during the 11:59:59 to 12:00:00 transition, he or she just may get two different days.

Good luck.

My work in progress. I hate JS. :P

Report •

Related Solutions

Ask Question