Jump to content

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
https://forums.phpfreaks.com/topic/275226-matching-two-strings/
Share on other sites

When you really want to know exactly what a function contains, it is generally var_dump that you want to use. Add an echo "<pre>"; in front of it, or check the page source, to see all whitespace as well. (Browsers tends to collapse whitespace into a single space, after all.)

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
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.