I have a comparison of 2 variables in a script, and am not getting the desired results, and wondered what the simplest comparison would be to obtain those results...

$username='TestName';
$user='testname';

  if ($username==$user){
    print "This is the result I want." ;
  }else{
    print "This isn't the result I want." ;
    }

How do I do the comparison and have it disregard the upper/lower case issue?

Recommended Answers

All 3 Replies

What's wrong with the code you have there? It works!

If you want them to be equal despite the capital & lower case letters; you'll have to do some manipulation of the data before you compare them.

string strtolower ( string $variable )

The above statement will convert a given variable to all lower cases; now you can do the comparison without having to worry about the upper/lower cases.

I have a comparison of 2 variables in a script, and am not getting the desired results, and wondered what the simplest comparison would be to obtain those results...

You could always change the string to lower case if you do not want to take case in to it:

$username='TestName';
$user='testname';

$username = strtolower($username);
$user = strtolower($user);

if ($username==$user){
    print "This is the result I want." ;
}else{
    print "This isn't the result I want." ;
}

Thank you both for your responses... That is exactly what I was looking for..

if (strtolower($username)==strtolower($user)){
  print"good match";
  }

I know there is almost always a simple resolution to the issues I run across, and this has become the greatest resource for resolving them.

Thanks Again,

Douglas

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.