Average Joe
Average Joe

Reputation: 4601

case insensitive comparing in PHP

Is there an operator in PHP that allows incasesensitive comparisons?

Instead of doing the following:

if (strtolower("A") == strtolower("a") )

I guess I'm looking for something like:

if ^("A" == "a")   

Where ^ tells php to ignore the case based comparison.

Yes, I do have a wild imagination. :)

Upvotes: 0

Views: 899

Answers (4)

knittl
knittl

Reputation: 265201

You can use stricmp

if(!strcasecmp('a', 'A')) echo 'strings are equal';

Upvotes: 3

Baba
Baba

Reputation: 95101

You can use http://www.php.net/manual/en/function.strcasecmp.php strcasecmp

if (strcasecmp("A", "a") == 0) {
    echo 'OK';
}

Thanks

:)

Upvotes: 1

Explosion Pills
Explosion Pills

Reputation: 191749

strcasecmp

Upvotes: 0

Daniel Lubarov
Daniel Lubarov

Reputation: 7924

You can use strcasecmp for this. Just check that it returns 0.

if (strcasecmp("A", "a") == 0) {
    // yes
}

Upvotes: 1

Related Questions