0

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?

3
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by showman13
0

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...

Edited by JameB

0

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." ;
}

Edited by Squidge

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.