Zugzwangle Posted June 18, 2010 Share Posted June 18, 2010 $parts[] is an array of the following: [Event \"90m + 5s, rated\" [site \"Main Playing Hall\" [Date \"2010.06.17\" [Round \"?\" [White \"Zugzwang1\" [black \"Jeff Morris\" [Result \"0-1\" [WhiteElo \"1189\" [blackElo \"1233\" [PlyCount \"30\" EventDate \"2010.06.17\" [EventType \"blitz\" [TimeControl \"60\" The first for statement below works.. the 2nd doesn't, yet $partsLocation and $correctLocation are the same value, as tested with an echo statement (echo ($partsLocation).'<br>'; echo ($correctLocation). <?php $correctControl = '[Event \"90m + 5s, rated\"'; $partsControl = $parts[0]; //echo ($partsControl.'<br>'); //echo ($correctControl.'<br>'); if ($partsControl == $correctControl) { echo ("Correct time control!!<br>"); } else { echo ("Time Control is wrong!!!"); } $correctLocation = '[site \"Room 1\"'; $partsLocation = $parts[1]; //echo ($partsLocation).'<br>'; //echo ($correctLocation); if ($partsLocation == $correctLocation) { echo "Correct Location"; } else { echo ("Location is wrong!!!<br>"); } ?> OUTPUTS: Correct time control!! Location is wrong!!! The first for statement works, and the 2nd doesn't.. I can't see why. Can you? Link to comment https://forums.phpfreaks.com/topic/205172-one-if-statement-works-one-doesnt/ Share on other sites More sharing options...
kenrbnsn Posted June 18, 2010 Share Posted June 18, 2010 Please dump the $parts array using <?php echo '<pre>' . print_r($parts,true) . '</pre>'; ?> and post the results here. Also, there could be some extraneous characters in the values that you're not seeing with your eye. Try the following "if" statemen: <?php if (trim($partsLocation) == trim($correctLocation)) { echo "Correct Location"; } else { echo ("Location is wrong!!!<br>"); } ?> Ken Link to comment https://forums.phpfreaks.com/topic/205172-one-if-statement-works-one-doesnt/#findComment-1073934 Share on other sites More sharing options...
Zugzwangle Posted June 18, 2010 Author Share Posted June 18, 2010 The output for the following: <?php echo '<pre>' . print_r($parts,true) . '</pre>'; ?> is Array ( [0] => [Event \"90m + 5s, rated\" [1] => [site \"Room 1\" [2] => [Date \"2010.06.18\" [3] => [Round \"?\" [4] => [White \"Zugzwang1\" [5] => [black \"Jeff Morris\" [6] => [Result \"1-0\" [7] => [WhiteElo \"1543\" [8] => [blackElo \"1537\" [9] => [PlyCount \"5\" [10] => [EventDate \"2010.06.18\" [11] => Link to comment https://forums.phpfreaks.com/topic/205172-one-if-statement-works-one-doesnt/#findComment-1073946 Share on other sites More sharing options...
Zugzwangle Posted June 18, 2010 Author Share Posted June 18, 2010 Thanks for that... 'trim' worked.. !! Thanks very much, that cost me a few hours!! Link to comment https://forums.phpfreaks.com/topic/205172-one-if-statement-works-one-doesnt/#findComment-1073947 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.