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. Quote 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] Quote 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 :( Quote Link to comment https://forums.phpfreaks.com/topic/8606-string-question/#findComment-31571 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.