I literally spent 6 hours trying to find this out. I have the code below:
$pieces3 = explode(":", $value2);
$checkiftime = $pieces3[0];
if ($checkiftime == 'time')
{
echo "Yes!";
}
else
{
echo "Oh no!";
}
$value2 contains:
" 'time': 1376952971"
I'm pretty sure the statement should be true but for some reasons, I keep getting false (oh no!)
if ($checkiftime == 'time')
What could be wrong? I already tried using double quotes for $checkiftime=="time" but still no avail.
EDIT:
I tried doing Vardumps after the explode:
var_dump($pieces3);
echo "<br>";
var_dump($value2);
echo "<br>";
var_dump($pieces3[0]);
echo "<br>";
And resulted with:
array(2) { [0]=> string(13) " 'time'" [1]=> string(11) " 1376952971" }
string(25) " 'time': 1376952971"
string(13) " 'time'"
I'm not sure why 'time' shows as String(13), I see that blank space, could that be a special character containing more than 1 hidden string? I did a trim() but it doesn't seem to change anything.
EDIT2:
Thanks everyone, below is the part of the code that I modified and it worked great:
$checkiftime = trim($pieces3[0], " '\t
\0\x0B");
if ($checkiftime == 'time')