tags:

views:

103

answers:

4

Both values are '2' but I am not getting a true. Why?

 echo $getuser. "<br />"; 
 echo $userurl. "<br />"; 
   if ($getuser == $userurl) {  
       echo "true <br />";
     }

Result

2
2
+1  A: 

When I try

$getuser = 2;
$userurl = 2;

echo $getuser. "<br />";
echo $userurl. "<br />";
if ($getuser == $userurl) {
    echo "true <br />";
}

Results:

2
2
true 

Works for me. On XAMPP (Windows) and Linux (Apache) alike. So there's problem probably somewhere in configuration or something...

Andrew
+4  A: 

Instead of echoing them out, use var_dump() to see exactly what is stored in those variables:

var_dump($getuser); echo "<br />";
var_dump($userurl); echo "<br />";
yjerem
I get 'string(1) "2" string(7) "2"'
patrick
that's crazy, the number in parentheses is the length of the string. so you've got some invisible characters or something. where are you getting your $userurl from??
yjerem
ok I know where they are coming from. I strip a URL from '/users/3104' to '3104' so I get rid of 7 chars by using '$userurl = substr($users['url'],7). "<br />";' I tried using trim($userurl, "\0") to get rid of NULL bytes but it's not working.
patrick
found the solution: '$userurl = ltrim($users['url'], " users/" );' Thanks!
patrick
Yep, gotta remember that with browser-based debugging, it's WYSIPNWYPI (what you see is probably not what you put in)
Marc B
@patrick: I don't think, that you want to do `ltrim($users['url'], " users/" )` (read carefully the docs: http://php.net/ltrim ). Apart from that, you should accept the answer, if it solved your problem (or put you on the right track).
Boldewyn
+4  A: 

You probably have some stray spaces or other characters which are not easy, or maybe not possible to visually detect.

use

var_dump($getuser);
var_dump($userurl);

Pay attention to the string length. Consider using trim() if needed

chris
+1 for specifically calling out whitespace. That was my hunch as well.
Frank Farmer
+3  A: 

may be contain dummy space in that, use like this

 echo $getuser. "<br />"; 
 echo $userurl. "<br />"; 
   if (trim($getuser) == trim($userurl)) {  
       echo "true <br />";
     }
Karthik