PHP如果准时

时间:2011-12-01 15:44:43

标签: php if-statement strtotime

$today=date("d");       # today
$startdate="14";        # start of advent 14th/13th
$enddate="25";          # end of advent 24th/25th
//strtomtime
?>
<!DOCTYPE HTML><html><head><meta charset="utf-8"><title>Christmas Advant Calendar</title></head><body>

<div class="adventframework">

    <?php
        /*$i=$startdate;
        while($i<=$enddate)
        {
            echo "<div class='datebox " . $i . "' id='" . $i ."'>";
            echo "Today is the " . $i . "";
            echo "</div>";
            $i++;
        }*/ 

        if ($startdate==$today){
            echo 'today and start date match';
        }

问题是今天是01而脚本回声:today and start date match$startdate是14时 - 我应该在这里使用strtotime;它去哪儿了?

2 个答案:

答案 0 :(得分:4)

问题是类型转换。

尝试

if ((int)$startdate == (int)$today)

更多设置$ startdate,如:

$startdate = 14; //instead of $startdate = "14"

答案 1 :(得分:1)

尝试使用strcmp()

if(strcmp($startdate, $today) === 0) { //strings match
    echo 'today and start date match';
}

演示:http://codepad.org/lN90FUSa