Jump to content

One 'if' statement works, one doesn't!


Zugzwangle

Recommended Posts

$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
Share on other sites

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
Share on other sites

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
Share on other sites

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.