Case insensitive string comparison

前端 未结 6 1247
醉梦人生
醉梦人生 2020-12-01 10:25

I would like to compare two variables to see if they are the same, but I want this comparison to be case-insensitive.

For example, this would be case sensitive:

6条回答
  •  鱼传尺愫
    2020-12-01 10:38

    This is fairly simple; you just need to call strtolower() on both variables.

    If you need to deal with Unicode or international character sets, you can use mb_strtolower().

    Please note that other answers suggest using strcasecmp()—that function does not handle multibyte characters, so results for any UTF-8 string will be bogus.

提交回复
热议问题