开发者

Show a different template after two days in php with date()

I have this code to capture a date and time:

date('F j, Y, g:i a T')

and save is as

$datetime:

and I have this code to include a template:

function template_contents($file, $model) {
    if (!is_file($file)) {
        throw new Exception("Template not found");
    }
    ob_start();
    include $file;
    $contents2 = ob_get_contents();
    ob_end_clean();

   开发者_JS百科 return $contents;
}

if($datetime == "No Date Yet"){
    echo template_contents("post.php", $model);
} elseif($datetime == "June 2, 2010, 2:55 pm MDT"){
    echo template_contents("notpost.php", $model);
}else {
    echo template_contents("post.php", $model);
}

And I as hoping to edit the elseif statement to show the notpost.php template if the $datetime was less than 2 days. So, notpost.php shows up for two days and post.php shows up after two days.


Change the elseif statement to:

} elseif (time() <= strtotime("June 2, 2010, 2:55 pm MDT")) {

This shows notpost.php if the current time (given by time()) is earlier than the given time.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜