dmccabe Posted September 26, 2008 Share Posted September 26, 2008 I have the following code: $newfirstletter = substr($row['name'], 0,1); if ($newfirstletter != $firstletter) { $firstletter = $newfirstletter; It is taking the first letter of a word from the db and comparing it with the variable $newfirstletter then if they are different creating a new header. However if the letter is the same but the case is different it creates a new header anyway, how can I make it case-insensitive. Link to comment https://forums.phpfreaks.com/topic/125917-case-sensitive-variable-comparison/ Share on other sites More sharing options...
JonnoTheDev Posted September 26, 2008 Share Posted September 26, 2008 use the preg_match() function Link to comment https://forums.phpfreaks.com/topic/125917-case-sensitive-variable-comparison/#findComment-651126 Share on other sites More sharing options...
GingerRobot Posted September 26, 2008 Share Posted September 26, 2008 I'd do something like this: $str = 'hello'; $char = 'H'; if(strcasecmp($str[0],$char) == 0){ echo 'true'; }else{ echo 'false'; } Link to comment https://forums.phpfreaks.com/topic/125917-case-sensitive-variable-comparison/#findComment-651142 Share on other sites More sharing options...
JonnoTheDev Posted September 26, 2008 Share Posted September 26, 2008 Nice, never seen that function Link to comment https://forums.phpfreaks.com/topic/125917-case-sensitive-variable-comparison/#findComment-651158 Share on other sites More sharing options...
dmccabe Posted September 26, 2008 Author Share Posted September 26, 2008 Excellent thanks I will give the strcasecmp function Link to comment https://forums.phpfreaks.com/topic/125917-case-sensitive-variable-comparison/#findComment-651162 Share on other sites More sharing options...
discomatt Posted September 26, 2008 Share Posted September 26, 2008 running strtolower/upper on both vars will work as well. Link to comment https://forums.phpfreaks.com/topic/125917-case-sensitive-variable-comparison/#findComment-651277 Share on other sites More sharing options...
genericnumber1 Posted September 26, 2008 Share Posted September 26, 2008 running strtolower/upper on both vars will work as well. though slightly slower unfortunately (we had a huge thread testing the speeds before of these same methods, hah). Link to comment https://forums.phpfreaks.com/topic/125917-case-sensitive-variable-comparison/#findComment-651306 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.