doni49 Posted March 3, 2007 Share Posted March 3, 2007 I've been trying to figure this out since last night. PLEASE help me find it. $la[0] contains X-Folder: but the if test seems to think that it doesn't. THis is a code snippet from my code. echo "Line" . $cnt++ . ": Part 0--" . $la[0] . "--Part 1--" . $la[1] . "--<br>\n"; produces this: Line16: Part 0--X-Folder:--Part 1--0-- But the following if test condition fails: if ($la[0] == "X-Folder:"){ $folder = $la[1]; echo "Line: " . $line; $tst = FALSE; } Quote Link to comment https://forums.phpfreaks.com/topic/41028-solved-if-condition-fails-even-though-it-should-run/ Share on other sites More sharing options...
Barand Posted March 3, 2007 Share Posted March 3, 2007 Is there any code between <?php echo "Line" . $cnt++ . ": Part 0--" . $la[0] . "--Part 1--" . $la[1] . "--<br>\n"; ?> and <?php if ($la[0] == "X-Folder:"){ $folder = $la[1]; echo "Line: " . $line; $tst = FALSE; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/41028-solved-if-condition-fails-even-though-it-should-run/#findComment-198819 Share on other sites More sharing options...
mainewoods Posted March 3, 2007 Share Posted March 3, 2007 display it's value just before your test: echo "showvalue: " . $la[0]; if ($la[0] == "X-Folder:"){ $folder = $la[1]; echo "Line: " . $line; $tst = FALSE; } Quote Link to comment https://forums.phpfreaks.com/topic/41028-solved-if-condition-fails-even-though-it-should-run/#findComment-198845 Share on other sites More sharing options...
doni49 Posted March 4, 2007 Author Share Posted March 4, 2007 Is there any code between <?php echo "Line" . $cnt++ . ": Part 0--" . $la[0] . "--Part 1--" . $la[1] . "--<br>\n"; ?> and <?php if ($la[0] == "X-Folder:"){ $folder = $la[1]; echo "Line: " . $line; $tst = FALSE; } ?> Nope. Just a comment. I put the echo line in there because I wanted to confirm that the $la array had what I thought it did. Here's the more of the code just copy pasted. echo "Line" . $cnt++ . ": Part 0--" . $la[0] . "--Part 1--" . $la[1] . "--<br>\n"; // echo "Line" . $cnt++ . ": " . $line[$cnt] . "<br>\n"; if ($la[0] == "X-Folder:"){ $folder = $la[1]; echo "Line: " . $line; $tst = FALSE; } I put the dashes before and after the variable because I wanted to see if there were any extra characters in there. Thanks guys! display it's value just before your test: That's what the echo line that I have is for. Thanks all for the assistance--this one's been bugging me and I'm sure it's probably a simple typo somewhere. But I've been looking at it for so long, I'm not sure I'll be able to see it myself. Quote Link to comment https://forums.phpfreaks.com/topic/41028-solved-if-condition-fails-even-though-it-should-run/#findComment-198877 Share on other sites More sharing options...
AndyB Posted March 4, 2007 Share Posted March 4, 2007 I suspect that $la[0] might contain some leading or trailing blanks, or it's managed to get some non-printing control character (or MS Word garbage) in there perhaps. Test it thoroughly by echoing the value AND the length of the string. Quote Link to comment https://forums.phpfreaks.com/topic/41028-solved-if-condition-fails-even-though-it-should-run/#findComment-198884 Share on other sites More sharing options...
doni49 Posted March 4, 2007 Author Share Posted March 4, 2007 Thanks for the suggestion Andy. You were right. Now I just need to figure out WHY. I (or actually my PHP script) wrote the text file that this is coming from. I'm reading a text file in and trying to pull out the value that follows the colon on the following line. X-Folder: 0 Here's the code that wrote this line to the file. $hdrs[$i-1] = "X-Folder: " . $folder ."\n\n"; $headers = implode("\n", $hdrs); $fname = time(); $filePath = $path . $folders[$folder] . "/"; $filenameTMP = $filePath . "tmp/" . $fname; if (!$handle = fopen($filenameTMP, 'w')) { echo "Cannot open file ($filenameTMP)"; exit; } // Write $somecontent to our opened file. $content = $headers . $message; if (fwrite($handle, $content) === FALSE) { echo "Cannot write to file ($filenameTMP)"; exit; } fclose($handle); Quote Link to comment https://forums.phpfreaks.com/topic/41028-solved-if-condition-fails-even-though-it-should-run/#findComment-198905 Share on other sites More sharing options...
doni49 Posted March 4, 2007 Author Share Posted March 4, 2007 P.S. I used strlen on both. strlen($la[0]); // <--returns 13 and strlen("X-Folder:");// <--returns 9 Quote Link to comment https://forums.phpfreaks.com/topic/41028-solved-if-condition-fails-even-though-it-should-run/#findComment-198909 Share on other sites More sharing options...
AndyB Posted March 4, 2007 Share Posted March 4, 2007 ... wonder if those 'extra' four characters are \r\n in your text file Quote Link to comment https://forums.phpfreaks.com/topic/41028-solved-if-condition-fails-even-though-it-should-run/#findComment-198931 Share on other sites More sharing options...
doni49 Posted March 4, 2007 Author Share Posted March 4, 2007 Interesting theory. But: 1) I thought \n was seen as ONE LINE. A new-line character. 2) the $la array variable was created from this code: $la = explode(" ",$lines[$cnt]); So if anything the newline would be at the end of $la. I was getting ready to post that--but decided to try something first. $l = strlen("\n\nX-Folder:"); // <--returns 11 instead of 9 and changed the if condition to this. if ($la[0] == "\n\nX-Folder:") //<--still doesn't run. Quote Link to comment https://forums.phpfreaks.com/topic/41028-solved-if-condition-fails-even-though-it-should-run/#findComment-198936 Share on other sites More sharing options...
doni49 Posted March 4, 2007 Author Share Posted March 4, 2007 found it there was a typo in the echo statement that's inside of the if statement. Since it wasn't displaying what I expected, I didn't think it was working. Thanks for the assistance! Quote Link to comment https://forums.phpfreaks.com/topic/41028-solved-if-condition-fails-even-though-it-should-run/#findComment-198950 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.