1vannn
1vannn

Reputation: 59

When comparing in if statements in PHP, would it be case sensitive?

If I had a code like, if ($_REQUEST['carrier'] == "T-Mobile") {} could I not have to do "t-mobile" as well if someone for example, forgets to capitalize they're carrier name? I am writing an email text subscription system.

Upvotes: 0

Views: 161

Answers (4)

hudolejev
hudolejev

Reputation: 6018

strtolower:

if (strtolower($_REQUEST['carrier']) == "t-mobile") { /* ... */ }

There are more elegant ways to do it, but you get the idea.

Upvotes: 0

joaopribs
joaopribs

Reputation: 658

You can use the strcasecmp function to check if the two strings are equal (case insensitive).

If they are equal, this function returns 0.

Take a look here: http://php.net/manual/en/function.strcasecmp.php

Your if would look like this

if (strcasecmp($_REQUEST['carrier'], "T-Mobile") == 0)

Upvotes: 1

Polynomial
Polynomial

Reputation: 28316

Yes, it's case sensitive. The solution is to convert the input to lowercase:

if (strtolower($_REQUEST['carrier']) == "t-mobile") {

Upvotes: 0

Lighthart
Lighthart

Reputation: 3656

I cant' really figure out your question but...

Try to convert both to lower case and compare thusly.

Upvotes: 0

Related Questions