Jump to content

[SOLVED] Comparing two variables that aren't case sensitive..


Recommended Posts

As it stands, in PHP, "this" doesn't equal "This".

 

But what if I want "this" to equal "This" but "this" should still not equal "That".

 

You know what I mean? I want to compare to variables to see if they are the same, disregarding their case.

 

Is there a way to do this?

 

Thanks!

this will mind blow you there you go

 

<?php

$a="the";
$b="The";

// the the correct

if ( $a==strtolower($b)) {

echo correct;

}elseif($b==strtolower($a)){

echo correct;
}else{

echo wrong;
}


?>

 

That won't work unless at least one of the variables is all lower case. This seems a more simple and fool proof method:

 

<?php

Why not just

if (strtolower($a) == strtolower($b)) {
  //They are equal disregarding case
} else {
  //Not equal
}
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.