-1

So I have this line in .txt file:

<strong>Position Id:</strong> P0001
<strong>Title:</strong> Sale Clerks
<strong>Description:</strong> do something  
<strong>Closing Date:</strong> 25/09/2013   
<strong>Position:</strong> Full-Time    
<strong>Contract:</strong> On-Going 
<strong>Applicated by:</strong> Post
<strong>Location:</strong> NSW

I want to compare the closing date in text file with current server date.this is what i have so far and strtotime wouldn't print out anything.

P.S: I have to explode the file for other reason too.

if(isset($_GET["title"])){
        $title = $_GET["title"];
        $cri = $_GET["criteria"];
        $err1 = "";
        $err2 = "";
        if(strlen($title) == 0){
            $err1 = "Please Enter Title For Searching";
            echo"<p> ",$err1,"</p>";
            return;
        }
        $file = "../data/jobs.txt";
        if(! file_exists($file)){
            $err2 = "The Job Text File Is not Exist!!!";
            echo"<p> ",$err2,"</p>";
            return;
        }
        if($err1 == "" && $err2 == ""){
            $count = 0;
            $alljobs = file($file);
            for($i = 0;$i < count($alljobs);$i++){
                $collumns = explode("\t",$alljobs[$i]);
                $colTit = explode(":",$collumns[1]);
                $colPos = explode(":",$collumns[4]);
                $colCon = explode(":",$collumns[5]);
                $colApp = explode(":",$collumns[6]);
                $colLoca = explode(":",$collumns[7]);
                $timeValue = explode(":",$collumns[3]);
                echo strtotime($timeValue[1]);
4

2 回答 2

0

$timeValue[1]

将包含

</strong> 25/09/2013  

你应该删除

</strong>

细绳

于 2013-09-26T04:23:12.173 回答
0

假设$timeValue确实包含文件中的日期字符串,那么使用日期格式d/m/Y将遇到问题,strtotime()因为它将模糊日期9/3/2013视为m/d/Y格式。

您应该改用DateTime::createFromFormat,例如

$closingDate = DateTime::createFromFormat('d/m/Y', $timeValue[1]);

然后,您可以轻松地将其与您的服务器时间进行比较

$diff = $closingDate->diff(new DateTime());
于 2013-09-26T04:24:05.727 回答