Disable case sensitive only in a comparison

1

I would like to know if there is a way to "disable" case sensitive in a particular comparison.

Example:

var_dump('SQL'=='SQL'); # bool(true)

var_dump('SQL'=='sQL'); # bool(false)

I know there are ways to resolve, one of them with strtoupper() or strtolower() , but would like to know specifically if you have to disable directly in a comparison.

    
asked by anonymous 07.08.2018 / 15:02

2 answers

2

Directly not, but a function that performs the insensitive comparison, such as strcasecmp , can be used. As you have already mentioned, you can also manipulate the strings to do the manipulation, using strtoupper and strolower .

You can use the strcasecmp function as follows:

if (strcasecmp("sQl", "SQL") == 0) {
    echo 'São iguais';
}

When the function return is 0 it is because the two strings are equal. When the first string is less than the second, the return will be < 0. And when the second string is less than the first, the return will be > 0. You can see more about the PHP documentation function.

    
07.08.2018 / 15:19
0

The short answer is no

But as you said, you can pass the two values to strtoupper or strolower and make the comparison, or if you want to use regex you can pass the / i modifier too.

    
07.08.2018 / 15:12