Just use date()
to format the date to match your file naming scheme.
$filename = sprintf('%s.php', date('n-j-Y'));
include($filename);
سؤال
I have 365 php pages already created for next year currently named:
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?
المحلول
Just use date()
to format the date to match your file naming scheme.
$filename = sprintf('%s.php', date('n-j-Y'));
include($filename);