Jump to content

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


bobleny

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
}
?>

Archived

This topic is now archived and is closed to further replies.

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