View Full Version : Using php to change content depending on day of week

12-21-2010, 01:30 AM
So I'm setting up a specials page in my beta website. I've been teaching myself most of the building and this is my only problem left.

So what I need is some type of scripting to grab information for example Monday and post it when monday comes around. Then Tuesday it grabs tuesday information and etc etc.


12-21-2010, 02:03 AM
I assume you're already using PHP on your page, so your page is
probably called "index.php" instead of "index.html"?

You'll use the PHP date function to get the "day of week".
It will be based off of your webhost's timezone (unless it's really
important to use your own).

You didn't specify how your "information" is stored.
A text file, something in a database??


// Get day of week (0=SUN, 1=MON ... 6=SAT)

// What to do with it ... not enough information from you to determine this part ...
if($day == 0){
// it's Sunday
if($day == 1){
// it's Monday

// etc.


12-21-2010, 02:07 AM
All my information is in a .txt file on the server. Should I continue to use this file or should I change it to a different format.

12-21-2010, 02:56 AM
.txt is fine ...
Do you have that part figured-out already?
You're able to display the text you want?

12-21-2010, 03:08 AM
yeah I think I figured it out I decided not to use a back end database. Instead I'm using a echo function so it prints the special. Thanks so much.

12-21-2010, 04:11 PM
If you were to code several .txt files like ...

t0.txt, t2.txt, t7.txt ...

You could automatically reference it by using that digit ...



// anywhere on your page, you include the file.


Your page .. blah blah<br><br>

<?php include($file);?>

blah blah<br><br>