高分求:PHP函数,根据发布日期长短显示new标志

来源:百度知道 编辑:UC知道 时间:2024/06/05 02:07:51
高分求了啊
我想实现一个功能,如果发布文章的日期已经过去一周就不要new标志,如果是一周之内发布的就加上new标志。应该如何写呢?
要求是php的,谢谢了

// 方法很多
// 简单点的就用时间戳 time(); 表示吧
// 比如说 你添加文章表添加个时间戳 字段, adtime ;
// 我先用 文件 来给你做个 例子 ,
// 先运行 addnews.php 不现在时间戳 写入, 在运行 shownews.php
// 写文章 addnews.php

<?php
$nowTime = time(); // 这个 是你写入文章时候的时间戳!
$rs = fopen('nowtime.txt','w+');
fwrite($rs, $nowTime);
fclose($rs);
?>

// 查看 文章是否过时 shownews.php
<?php
$addtime = file_get_contents('nowtime.txt'); // 获取 文章写入时候的时间戳

$ctime = 5; // 1等于 1秒 7天等于 7*24*3600 为了让你在短时间内看到效果,我先设置为 30秒

if(($addtime+$ctime) > time() )
{
echo 'New';
}
else
{
echo "超过{$ctime}秒";
}
?>

<?php
//假设日期格式为xxxx-xx-xx ...
$date = strtotime($news['createDate']);
if ((time() - $date)<7*24*3600)
$is_new = true;
else
$is_new = false;
?>

function checknew($posttime){
global $timestamp;
return $time