Mateobus Posted April 28, 2006 Share Posted April 28, 2006 I just want to do a Boolean check of a string that returns true if the last two characters of the string are upper case and false otherwise. Thanks. Link to comment https://forums.phpfreaks.com/topic/8606-string-question/ Share on other sites More sharing options...
toplay Posted April 28, 2006 Share Posted April 28, 2006 You can do it with preg_match() too, but this is probably one of the easiest ways:[code]$text = 'abCD';// Make sure the string is always 2 characters or more otherwise substr() returns falseif (ctype_upper(substr($text, -2)) { echo "The string $text last 2 characters consists of uppercase letters.\n"; } else { echo "The string $text last 2 characters do not consist of uppercase letters.\n"; }[/code] Link to comment https://forums.phpfreaks.com/topic/8606-string-question/#findComment-31570 Share on other sites More sharing options...
.josh Posted April 28, 2006 Share Posted April 28, 2006 <?php$blah = "abcdef";$test = substr($blah, -2); if (ctype_upper($test)) { echo "letters are uppercase";}else { echo "letters are not uppercase"; }?>edit: gah! you beat me :( Link to comment https://forums.phpfreaks.com/topic/8606-string-question/#findComment-31571 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.