Deniz Zoeteman Deniz Zoeteman - 1 year ago 171
PHP Question

Case insensitive string comparison

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:

if($var1 == $var2){

But I want this to be case insensitive, how would I approach this?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download