Case insensitive string comparison

前端 未结 6 1257
醉梦人生
醉梦人生 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

    strcasecmp() returns 0 if the strings are the same (apart from case variations) so you can use:

    if (strcasecmp($var1, $var2) == 0) {
    }
    

提交回复
热议问题