Php 如果日期是从现在起的10天,考虑为新标题
在我的新闻脚本中,我将新闻组织为.txt文件,在每个新闻文件的开头都有[20.03.13](例如)日期格式 我需要一个小的,如果这将检查日期是否有X天的金额回来(如-10)。 如果是这样,它将被添加到最新的新闻中。 现在设置为如果日期为=今天的日期,则添加到最新新闻 我怎样才能把它转换成,如果从今天开始的10天内,日期变小了,echo。。。然后我们可以把今天的线路改成最新的 这是密码,谢谢。 顺便说一下,请尽量减少我脚本中的更改。我花了一段时间才写下来并理解它。。。我不是很好,有时人们会为你重写很多东西,不要花太多的精力,只要有用,我会感谢任何帮助:)再次感谢Php 如果日期是从现在起的10天,考虑为新标题,php,Php,在我的新闻脚本中,我将新闻组织为.txt文件,在每个新闻文件的开头都有[20.03.13](例如)日期格式 我需要一个小的,如果这将检查日期是否有X天的金额回来(如-10)。 如果是这样,它将被添加到最新的新闻中。 现在设置为如果日期为=今天的日期,则添加到最新新闻 我怎样才能把它转换成,如果从今天开始的10天内,日期变小了,echo。。。然后我们可以把今天的线路改成最新的 这是密码,谢谢。 顺便说一下,请尽量减少我脚本中的更改。我花了一段时间才写下来并理解它。。。我不是很好,有时人们会为你重写
<?
$files = array();
if($handle = opendir( 'includes/news' )) {
while( $file = readdir( $handle )) {
if ($file != '.' && $file != '..') {
// let's check for txt extension
$extension = substr($file, -3);
// filename without '.txt'
$filename = substr($file, 0, -4);
if ($extension == 'txt')
$files[] = $filename; // or $filename
}
}
closedir($handle);
}
rsort($files);
foreach ($files as $file)
{
// get post date
$postdate = substr($file, 0, 10);
// get todays date
$todaysdate = date("[d.m.y]");
if($postdate == $todaysdate)
{
echo "<h3 style=\"border-bottom: 1px solid #fff;\">• FROM TODAY:</h3>";
echo "<a href=\"?module=news&read=$file\"><h2 style=\"background:url('images/h2today.jpg') no-repeat;\">$file</h2></a>";
echo "<h3 style=\"border-bottom: 1px solid #fff;\">• FROM EARLIER:</h3>";
}
else
{
echo '<a href="?module=news&read=' . $file . '"><h2 style="margin: 4px;">' . $file . "</h2></a>";
}
}
?>
strotime
可以帮助您()。这将以您正在使用的[d.m.y]
格式格式化10天前的日期:
$todaysdate = date("[d.m.y]",strtotime("10 days ago"));
strotime
可以帮助您()。这将以您正在使用的[d.m.y]
格式格式化10天前的日期:
$todaysdate = date("[d.m.y]",strtotime("10 days ago"));
strotime
可以帮助您()。这将以您正在使用的[d.m.y]
格式格式化10天前的日期:
$todaysdate = date("[d.m.y]",strtotime("10 days ago"));
strotime
可以帮助您()。这将以您正在使用的[d.m.y]
格式格式化10天前的日期:
$todaysdate = date("[d.m.y]",strtotime("10 days ago"));
使用
使用
使用
使用
首先,我们将日期转换为标准格式,然后将其转换为Unix时间戳:
$postdate = substr($file, 0, 10);
//Removing the '[' ']' characters...
$postdate = str_replace(array('[', ']'), '', $postdate);
//Splitting the date into an array
$postdate = explode('.', $postdate);
//Now we have an array with this format: array(0 => 'day', 1 => 'month', 2 => 'year');
//Let's convert the year to 20xx (two thousand and blabla)...
$postdate[2] = '20'.$postdate[2]; //You'll have to change this line in 87 years =D
//Now we join our date array in a string with the following format: Y-m-d
$postdate = implode('-', array_reverse($postdate)); //We have to reverse the array because 'year' comes first.
//And now we convert the date to Unix timestamp
$postdate = strtotime($postdate);
//And finally we can check if the post time is bigger or equal than [now minus 10 days]:
$time_now = time();
if (($time_now - (3600*24*10)) <= $postdate)
{
//Passed, the rest of my script goes here
}
else //(Optional)
{
//The news has been posted more than 10 days ago
}
$postdate=substr($file,0,10);
//正在删除“['']”字符。。。
$postdate=str_replace(数组('[',']'),'$postdate);
//将日期拆分为数组
$postdate=分解('.',$postdate);
//现在我们有了一个具有这种格式的数组:数组(0=>'day',1=>'month',2=>'year');
//让我们把这一年换算成20xx年(两千年)。。。
$postdate[2]=“20”。$postdate[2]//你必须在87年后改变这条线
//现在,我们以以下格式将日期数组加入字符串:Y-m-d
$postdate=内爆('-',数组_反向($postdate))//我们必须反转数组,因为“年”是第一位的。
//现在我们将日期转换为Unix时间戳
$postdate=strottime($postdate);
//最后,我们可以检查post时间是否大于或等于[现在减去10天]:
$time_now=time();
如果($time_now-(3600*24*10))那么,首先让我们将日期转换为标准格式,然后将其转换为Unix时间戳:
$postdate = substr($file, 0, 10);
//Removing the '[' ']' characters...
$postdate = str_replace(array('[', ']'), '', $postdate);
//Splitting the date into an array
$postdate = explode('.', $postdate);
//Now we have an array with this format: array(0 => 'day', 1 => 'month', 2 => 'year');
//Let's convert the year to 20xx (two thousand and blabla)...
$postdate[2] = '20'.$postdate[2]; //You'll have to change this line in 87 years =D
//Now we join our date array in a string with the following format: Y-m-d
$postdate = implode('-', array_reverse($postdate)); //We have to reverse the array because 'year' comes first.
//And now we convert the date to Unix timestamp
$postdate = strtotime($postdate);
//And finally we can check if the post time is bigger or equal than [now minus 10 days]:
$time_now = time();
if (($time_now - (3600*24*10)) <= $postdate)
{
//Passed, the rest of my script goes here
}
else //(Optional)
{
//The news has been posted more than 10 days ago
}
$postdate=substr($file,0,10);
//正在删除“['']”字符。。。
$postdate=str_replace(数组('[',']'),'$postdate);
//将日期拆分为数组
$postdate=分解('.',$postdate);
//现在我们有了一个具有这种格式的数组:数组(0=>'day',1=>'month',2=>'year');
//让我们把这一年换算成20xx年(两千年)。。。
$postdate[2]=“20”。$postdate[2];//87年后您必须更改此行=D
//现在,我们以以下格式将日期数组加入字符串:Y-m-d
$postdate=内爆('-',array_reverse($postdate));//我们必须反转数组,因为“年”是第一位的。
//现在我们将日期转换为Unix时间戳
$postdate=strottime($postdate);
//最后,我们可以检查post时间是否大于或等于[现在减去10天]:
$time_now=time();
如果($time_now-(3600*24*10))那么,首先让我们将日期转换为标准格式,然后将其转换为Unix时间戳:
$postdate = substr($file, 0, 10);
//Removing the '[' ']' characters...
$postdate = str_replace(array('[', ']'), '', $postdate);
//Splitting the date into an array
$postdate = explode('.', $postdate);
//Now we have an array with this format: array(0 => 'day', 1 => 'month', 2 => 'year');
//Let's convert the year to 20xx (two thousand and blabla)...
$postdate[2] = '20'.$postdate[2]; //You'll have to change this line in 87 years =D
//Now we join our date array in a string with the following format: Y-m-d
$postdate = implode('-', array_reverse($postdate)); //We have to reverse the array because 'year' comes first.
//And now we convert the date to Unix timestamp
$postdate = strtotime($postdate);
//And finally we can check if the post time is bigger or equal than [now minus 10 days]:
$time_now = time();
if (($time_now - (3600*24*10)) <= $postdate)
{
//Passed, the rest of my script goes here
}
else //(Optional)
{
//The news has been posted more than 10 days ago
}
$postdate=substr($file,0,10);
//正在删除“['']”字符。。。
$postdate=str_replace(数组('[',']'),'$postdate);
//将日期拆分为数组
$postdate=分解('.',$postdate);
//现在我们有了一个具有这种格式的数组:数组(0=>'day',1=>'month',2=>'year');
//让我们把这一年换算成20xx年(两千年)。。。
$postdate[2]=“20”。$postdate[2];//87年后您必须更改此行=D
//现在,我们以以下格式将日期数组加入字符串:Y-m-d
$postdate=内爆('-',array_reverse($postdate));//我们必须反转数组,因为“年”是第一位的。
//现在我们将日期转换为Unix时间戳
$postdate=strottime($postdate);
//最后,我们可以检查post时间是否大于或等于[现在减去10天]:
$time_now=time();
如果($time_now-(3600*24*10))那么,首先让我们将日期转换为标准格式,然后将其转换为Unix时间戳:
$postdate = substr($file, 0, 10);
//Removing the '[' ']' characters...
$postdate = str_replace(array('[', ']'), '', $postdate);
//Splitting the date into an array
$postdate = explode('.', $postdate);
//Now we have an array with this format: array(0 => 'day', 1 => 'month', 2 => 'year');
//Let's convert the year to 20xx (two thousand and blabla)...
$postdate[2] = '20'.$postdate[2]; //You'll have to change this line in 87 years =D
//Now we join our date array in a string with the following format: Y-m-d
$postdate = implode('-', array_reverse($postdate)); //We have to reverse the array because 'year' comes first.
//And now we convert the date to Unix timestamp
$postdate = strtotime($postdate);
//And finally we can check if the post time is bigger or equal than [now minus 10 days]:
$time_now = time();
if (($time_now - (3600*24*10)) <= $postdate)
{
//Passed, the rest of my script goes here
}
else //(Optional)
{
//The news has been posted more than 10 days ago
}
$postdate=substr($file,0,10);
//正在删除“['']”字符。。。
$postdate=str_replace(数组('[',']'),'$postdate);
//将日期拆分为数组
$postdate=分解('.',$postdate);
//现在我们有了一个具有这种格式的数组:数组(0=>'day',1=>'month',2=>'year');
//让我们把这一年换算成20xx年(两千年)。。。
$postdate[2]=“20”。$postdate[2];//87年后您必须更改此行=D
//现在,我们以以下格式将日期数组加入字符串:Y-m-d
$postdate=内爆('-',array_reverse($postdate));//我们必须反转数组,因为“年”是第一位的。
//现在我们将日期转换为Unix时间戳
$postdate=strottime($postdate);
//最后,我们可以检查post时间是否大于或等于[现在减去10天]:
$time_now=time();
如果($time_now-(3600*24*10))
可能很难检查这些日期中哪一个更大,或者其他什么。但是如果您将它们转换为unixtimestamp,那么就完成了
这将是您的IF声明
if( (timestamp_today - numberof seconds in 10 days ) < timestamp_posted) { your code goes here }
现在使用mktime(0,0,0,$postdate[0],$postdate[1],$postdate[2])
但一定要把参数设置到位
可能很难检查这些日期中哪一个更大,或者其他什么。但是如果您将它们转换为unixtimestamp,那么就完成了
这将是您的IF声明
if( (timestamp_today - numberof seconds in 10 days ) < timestamp_posted) { your code goes here }
现在使用mktime(0,0,0,$postdate[0],$postdate[1],$postdate[2])
但一定要把参数设置到位
可能很难检查这些数据