Php 根据截止日期确定整数值?

Php 根据截止日期确定整数值?,php,date,Php,Date,不幸的是,我无法在我的Windows机器/IIS上安装XDebug来调试我的PHP,这使得事情变得非常困难 无论如何,我正在运行一个phpBB论坛,我正在尝试从包含线程/帖子的CSV文件集合导入数据。示例文件可能如下所示: A||N||1||username||Topic Title||||1 Z||000000||username||01-06-2017||03:30 PM||original post body Z||000001||anotherUsername||01-06-2017||

不幸的是,我无法在我的Windows机器/IIS上安装XDebug来调试我的PHP,这使得事情变得非常困难

无论如何,我正在运行一个phpBB论坛,我正在尝试从包含线程/帖子的CSV文件集合导入数据。示例文件可能如下所示:

A||N||1||username||Topic Title||||1 Z||000000||username||01-06-2017||03:30 PM||original post body Z||000001||anotherUsername||01-06-2017||03:42 PM||response post body 在我确定
$isArchiveThread
的值之后

我得到的输出如下:

[phpBB Debug]PHP注意:在第196行的文件[ROOT]/includes/functions_test.PHP中:无法将DateTime类的对象转换为int 1443657600

一,

它重复那些
[phpBB Debug]和
144367600
行**57**次,然后只打印一次
1`

我添加了几行代码,使我的代码只尝试读取前30个文件,这样我就可以看到输出。。。因此,如果它只循环了30次,我不知道为什么会得到115行输出(57*2+1)。

  • 抓取您的日期,即
    $explosion[3]
  • 将其转换为时间戳,使用
    strotime($explosion[3])
然后你有一个整数值,你可以和任何东西比较


或者,如果你像我一样完全懒惰,使用类似于碳的东西,你可以运行快速日期操作/比较

你是否响应了
($postedate<$dtCutoff)
结果?是真是假?无论哪种方式,该方程的值都应该告诉您什么是错误的,对吗?首先,请尝试使用
$dtCutoff=new DateTime($strutoff)
编辑了我的文章,其中包含
$dtCutoff
$isArchiveThread
的输出,使用Carbon或DateTime并不意味着你懒惰。。这意味着你做得对我认为这很有效。更新了我的脚本,现在正在运行。。。处理几千个文件并将它们全部插入数据库需要一段时间,但如果它起作用,我一定会回来接受你的答案。我通常不使用PHP;处理日期似乎比它应该做的要困难得多。至少,它是开箱即用的。
//Get file data for specific file
$fileContents = file($filename);

//Then split the data into an array
$explosion = explode("||", $fileContents[$i]);

//some logic to determine $forum_id for which Archive forum to insert the thread into, based on the directory containing $filename.

$postedDate = new DateTime(str_replace("-", "/", $explosion[3]));
$strCutoff = "2015-10-01";
$dtCutoff = strtotime($strCutoff);

//If the post was created before 10/01/15, insert into archive forum.
//This means the current $forum_id determined above is accurate
$isArchiveThread = ($postedDate < $dtCutoff);

//If the post is NOT to be archived (aka, if it is ACTIVE), determine the new $forum_id
if ($isArchiveThread === false)
    $forum_id = $forum_id - 7; //Active ForumID = Archive ForumID minus 7.
echo $dtCutoff . "<BR>";
echo $isArchiveThread;