Created
March 14, 2019 19:06
-
-
Save Medalink/d080de002e559ebe4c80df861debf6b4 to your computer and use it in GitHub Desktop.
Determine if the first letter of a string is uppercase and is A-Z
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Determine if the first letter of a string is uppercase and is A-Z | |
* | |
* Note: we use ctype here as it uses the current locale to help with multi-language/emoji decoding. | |
* | |
* @param string $string | |
* @return bool | |
*/ | |
function isFirstLetterUppercase(string $string): bool | |
{ | |
// Grab our first letter | |
$firstLetter = substr($string, 0, 1); | |
// True when both uppercase and A-Z passes | |
return ctype_upper($firstLetter) && ctype_alpha($firstLetter); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment