PHP 中的 == 是区分大小写的字符串比较吗?
我在 php.net 上找不到这个。在 PHP 中用于比较字符串时,双等号 (==
) 是否区分大小写?
I was unable to find this on php.net. Is the double equal sign (==
) case sensitive when used to compare strings in PHP?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
是的,
==
区分大小写。您可以使用
strcasecmp
进行不区分大小写的比较Yes,
==
is case sensitive.You can use
strcasecmp
for case insensitive comparison是的,但它会逐字节进行比较。
如果您要比较 unicode 字符串,您可能希望首先对它们进行规范化。请参阅
Normalizer
类。示例(以 UTF-8 输出):
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):
是的,
==
区分大小写。顺便说一句,对于不区分大小写的比较,请使用
strcasecmp
:Yes,
==
is case sensitive.Incidentally, for a non case sensitive compare, use
strcasecmp
:==
区分大小写,是的。要不敏感地比较字符串,可以使用
strtolower($x) == strtolower($y)
或strcasecmp($x, $y) == 0
==
is case-sensitive, yes.To compare strings insensitively, you can use either
strtolower($x) == strtolower($y)
orstrcasecmp($x, $y) == 0
==
区分大小写,一些其他操作数来自 php 手册,以熟悉http://www.php.net/manual/en/language.operators.comparison.php
==
is case sensitive, some other operands from the php manual to familiarize yourself withhttp://www.php.net/manual/en/language.operators.comparison.php
是的,
==
区分大小写。对我来说最简单的方法是转换为大写然后进行比较。例如:我希望它有效!
Yes,
==
is case sensitive. The easiest way for me is to convert to uppercase and then compare. In instance:I hope it works!
您可以尝试与哈希函数进行比较
You could try comparing with a hash function instead