Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

Matching two strings

$
0
0

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.


Viewing all articles
Browse latest Browse all 13200

Trending Articles