leke Posted March 4, 2013 Share Posted March 4, 2013 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 stringSkipped 2013-4-4 is a stringSkipped 2013-3-4 is a stringSkipped 2012-3-4 is a stringSkipped 2013-3-5 is a stringSkipped 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. Quote Link to comment Share on other sites More sharing options...
Jessica Posted March 4, 2013 Share Posted March 4, 2013 Try trimming the values. trim Quote Link to comment Share on other sites More sharing options...
Jessica Posted March 4, 2013 Share Posted March 4, 2013 Also you can use one call to date() with all three year month day. Quote Link to comment Share on other sites More sharing options...
leke Posted March 4, 2013 Author Share Posted March 4, 2013 Thanks, trim() worked, and yeah, you were right about the date() thing too Would it have been a \n that needed trimming on those array elements? Thanks again Quote Link to comment Share on other sites More sharing options...
Jessica Posted March 4, 2013 Share Posted March 4, 2013 You could try htmlentities() to see what was in there. Quote Link to comment Share on other sites More sharing options...
leke Posted March 4, 2013 Author Share Posted March 4, 2013 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(). Quote Link to comment Share on other sites More sharing options...
Jessica Posted March 4, 2013 Share Posted March 4, 2013 that was definitely not the right function, no idea why I told you that. sorry. I'm sure it's the newline. Quote Link to comment Share on other sites More sharing options...
Christian F. Posted March 4, 2013 Share Posted March 4, 2013 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.) Quote Link to comment Share on other sites More sharing options...
Jessica Posted March 4, 2013 Share Posted March 4, 2013 I originally thought var_dump but I wasn't sure it would show the \n but I'm also trying to do two things at once right now. Thanks Christian :-P Quote Link to comment Share on other sites More sharing options...
Christian F. Posted March 4, 2013 Share Posted March 4, 2013 Hehe, you're most welcome. *Christian bows with a theatrical gesture of his hand. Quote Link to comment Share on other sites More sharing options...
Barand Posted March 4, 2013 Share Posted March 4, 2013 // read YYYY-MM-DD lines of file to an array. so why are you formatting yours as YYYY-M-D Quote Link to comment Share on other sites More sharing options...
leke Posted March 4, 2013 Author Share Posted March 4, 2013 (edited) so why are you formatting yours as YYYY-M-D To be honest, I didn't really give it much thought 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 March 4, 2013 by leke Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.