Similar string not matched?

Hi

Can someone please explain why it prints 2?


<?php
if ('&#65279;EMAIL' == 'EMAIL'){
print "1";
}else{
print "2";
}
?>

Thanks

It shouldnt.

You sure you’re copying and pasting correctly?

@phantom007 ; surely you are over-simplifying your code when pasting it here, because I can’t see any valid reason to have that sort of IF statement as presented in a production code base.

Can you provide the actual IF statement so we can see the variables in use, how they are assigned, etc? As chances are the problem is you are assuming its value is ‘EMAIL’ which should equal ‘EMAIL’ but in all reality it isn’t. Have you done a var_dump($var) to see if it really did contain ‘EMAIL’?

That IS the actual thing, and I posted it here because I could not find any reason why it would not match. I mean both are simple strings. If you copy/paste my above code and try it on ur end, it will not work.

I just wanna know the reason.

Thanks

You have a BOM in your first ‘EMAIL’ string. If you copy and paste your code into Notepad++ you get the following:

<?php
if ('?EMAIL' == 'EMAIL'){
print "1";
}else{
print "2";
}
?>

Remove the ? and it works fine. So just re-type your text and it will work.

BOM?

Err, wrong terminology on my part, but I’ll link to BOM anyway, because it is good to know.

Chances are you have a unicode or similar character hidden there next to the E or after the ’ that doesn’t show up in ASCII. Just wanted to correct myself, as others would :stuck_out_tongue:

Thanks for your kind help