Is == in PHP a case-sensitive string comparison?
Yes, but it does a comparison byte-by-byte.
If you're comparing unicode strings, you may wish to normalize them first. See the Normalizer
class.
Example (output in UTF-8):
$s1 = mb_convert_encoding("\x00\xe9", "UTF-8", "UTF-16BE");$s2 = mb_convert_encoding("\x00\x65\x03\x01", "UTF-8", "UTF-16BE");//look the same:echo $s1, "\n";echo $s2, "\n";var_dump($s1 == $s2); //falsevar_dump(Normalizer::normalize($s1) == Normalizer::normalize($s2)); //true
Yes, ==
is case sensitive.
Incidentally, for a non case sensitive compare, use strcasecmp
:
<?php $var1 = "Hello"; $var2 = "hello"; echo (strcasecmp($var1, $var2) == 0); // TRUE;?>