比较何时修改页面和当前日期

时间:2013-04-22 15:59:47

标签: php

我已将getlastmod函数添加到我的标题中,并在上次修改时显示所有页面。现在,如果页面在过去7天内被修改,我想在标题导航容器的每个页面链接中添加文本或小的新图标,否则不显示任何内容。我的逻辑是:(我不是程序员btw)

<?PHP
$date_modified = filemdate;
$current_date = date(Y,m,d);
$new = '/images/new.gif';

if {(current_date > date_modified + 7days);

echo "";

else {
echo $new;
}}
?>

//将$ new添加到header.php导航上的每个导航项目,如home(index.php),news(news.php),links(links.php) //容器。

2 个答案:

答案 0 :(得分:2)

filemdate是错误的功能

你应该使用

filemtime($filename)

然后用它来比较文件时间。

答案 1 :(得分:0)

这个小片段应该这样做:

// get timestamp of last modification
$last_modified = filemtime($filename);
// get timestamp of seven days ago
$seven_days_ago = strtotime('-7 days');

// perform the comparison
if ($last_modified >= $seven_days_ago) {
    echo '/images/new.gif';
}
相关问题