Question

I have 365 php pages already created for next year currently named:

  • 1-1-2015.php
  • 1-2-2015.php
  • 1-3-2015.php

I want to display a different one each day using <?php include("1-1-2015.php"); ?> on my home page, I have curenlty done somthing similar for days of the week using "if else"

<?php 
$today = date("l");
if($today == "Sunday") 
{
//do Sunday Thing
}
elseif($today == "Monday")
{
// do Monday Thing
} 
?>

Is there a better way to do this other than 365 if statements as i would like this to be future proof so it would just be a case of adding the next 365 pages in 2016?

Was it helpful?

Solution

Just use date() to format the date to match your file naming scheme.

$filename = sprintf('%s.php', date('n-j-Y'));
include($filename); 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top