Jump to content

Matching two strings


leke

Recommended Posts

Hi, For some I can't match these two strings...

 

$timestamp = mktime() + CURR_TIME_OFFSET * 3600;
$d = date('j', $timestamp);  
$m = date('n', $timestamp);  
$y = date('Y', $timestamp);
$isCancelledCheck = (string) "$y-$m-$d";
echo "Date: $isCancelledCheck is a " . gettype($isCancelledCheck) . "<br>";

$db_read = file('cancelled_dates.txt'); // read YYYY-MM-DD lines of file to an array.

foreach($db_read as $key => $val) {
    // iterate through each element of db_read
    if ($val == $isCancelledCheck){
        echo "<br> $val == $y-$m-$d";
    } else {
        echo "<br>Skipped $val";
    }    
}

print_r($db_read);
 

 

 

which returns...


 

Date: 2013-3-4 is a string

Skipped 2013-4-4 is a string
Skipped 2013-3-4 is a string
Skipped 2012-3-4 is a string
Skipped 2013-3-5 is a string
Skipped 2013-2-4 is a string

 

Array ( [0] => 2013-4-4 [1] => 2013-3-4 [2] => 2012-3-4 [3] => 2013-3-5 [4] => 2013-2-4 )

 

How come the string 2013-3-4 is not matched here?

 

Thanks.

Link to comment
Share on other sites

You could try htmlentities() to see what was in there.

htmlentities didn't show any newline evidence, but I noticed in the source output, the elements are formatted with a newline so I guess they hang around when using file(). 

Link to comment
Share on other sites

so why are you formatting yours as YYYY-M-D

To be honest, I didn't really give it much thought :D I was just going with something that works quick, then I usually play with it and make some changes to the formatting based on problems I might foresee. I usually go with year month day as it's usually the most computer friendly format (along with being quite readable and international), but I also see I made an error in the comment writing mm-dd instead of m-d.

Edited by leke
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.