bobleny Posted June 11, 2007 Share Posted June 11, 2007 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! Quote Link to comment https://forums.phpfreaks.com/topic/55033-solved-comparing-two-variables-that-arent-case-sensitive/ Share on other sites More sharing options...
redarrow Posted June 11, 2007 Share Posted June 11, 2007 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; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/55033-solved-comparing-two-variables-that-arent-case-sensitive/#findComment-272056 Share on other sites More sharing options...
bobleny Posted June 11, 2007 Author Share Posted June 11, 2007 Yeah, I figured I'd have to use strtolower(). I was hoping there was a better way to do it. Thanks... Quote Link to comment https://forums.phpfreaks.com/topic/55033-solved-comparing-two-variables-that-arent-case-sensitive/#findComment-272057 Share on other sites More sharing options...
redarrow Posted June 11, 2007 Share Posted June 11, 2007 have a look agin at the code it means the first letter iver way hase to be upper case or if both are upper case there wrong. Quote Link to comment https://forums.phpfreaks.com/topic/55033-solved-comparing-two-variables-that-arent-case-sensitive/#findComment-272058 Share on other sites More sharing options...
redarrow Posted June 11, 2007 Share Posted June 11, 2007 what are you trying to achive please. Quote Link to comment https://forums.phpfreaks.com/topic/55033-solved-comparing-two-variables-that-arent-case-sensitive/#findComment-272060 Share on other sites More sharing options...
Psycho Posted June 11, 2007 Share Posted June 11, 2007 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 } ?> Quote Link to comment https://forums.phpfreaks.com/topic/55033-solved-comparing-two-variables-that-arent-case-sensitive/#findComment-272062 Share on other sites More sharing options...
redarrow Posted June 11, 2007 Share Posted June 11, 2007 i agree only trying to help but wrong like your code. i am tired sorry. Quote Link to comment https://forums.phpfreaks.com/topic/55033-solved-comparing-two-variables-that-arent-case-sensitive/#findComment-272063 Share on other sites More sharing options...
AndyB Posted June 11, 2007 Share Posted June 11, 2007 The function exists - http://ca.php.net/manual/en/function.strcasecmp.php Quote Link to comment https://forums.phpfreaks.com/topic/55033-solved-comparing-two-variables-that-arent-case-sensitive/#findComment-272064 Share on other sites More sharing options...
bobleny Posted June 11, 2007 Author Share Posted June 11, 2007 The function exists - http://ca.php.net/manual/en/function.strcasecmp.php Very nice, that is what I was looking for! Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/55033-solved-comparing-two-variables-that-arent-case-sensitive/#findComment-272079 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.