PHP 如果特定日期到期,则不回显变量


php if specific date expires do not echo vars

我正在尝试弄清楚如果日期已过期,如何不回显变量。

我在下面的PHP显示:

比赛 1 - 2015 年 4 月 1 日

比赛 2 - 2015 年 4 月 8 日

所以我需要的是,如果当前日期是 2015 年 4 月 2 日,则匹配 1 不会回响。如果4月30日,什么都不会回响。

这是 php

<?php
$match1 = "Match 1 - April 1, 2015";
$match2 = "Match 2 - April 8, 2015";
?>
<?=$match1?>
<?=$match2?>

我查看了几个代码并自己尝试了一些,但没有任何效果。谢谢。

基本思想:

$expiration_date = strtotime("2 April 2015"); //converts your date into a unix timestamp
$time = time(); //current time in unix format
if ($time < $expiration_date){ // if the current time is less than expiration date do something
    echo $match1; // or whatever variable you wanted to echo 
} // if the current time is past the expiration date the if statement will evaluate to false and do nothing
我想

为未来的用户更新它。

如果您希望根据到期日期显示/隐藏特定的div,您可以在单独的 PHP 页面上创建div,然后将它们包含在您的 php 中,如下所示:

包括.php

<?php if (time() < strtotime("1 January 2016")){include('Div1.php');}?>

Div1.php

<div class="myclass">I want this Div included with Include.php if it is not expired past January 1 2016</div>

认为可能对某人有帮助。

这是另一个PHP代码,适用于那些想要在特定日期显示某个div的人,如果它不是在该日期,则默认为另一个div。

例如,我将其用于准备税收的网站(美国)。

报税季节从 1 月 1 日开始,到 4 月 15 日结束。客户需要在报税季节显示某个div,表明他们准备了税款,淡季,他们帮助设置会计软件。

**注意 - 请注意,结束日期是 04 月 15 日之后的 1 天,这是因为您必须在结束日期中添加 +1 天,以确保您的结束日期仍然有效才能显示。

.PHP

<?php
    if ((time() > strtotime("01/01/2015")) && (time() < strtotime("04/16/2015")))
    {include "seasonON.php";}else{include "seasonOFF.php";}
?> 

季节开.php

<div>YES, Tax season is here and we prepare Taxes!</div>

季休

.php
<div>Tax season is over, but we can help you with your accounting software</div>