Skip to content

Instantly share code, notes, and snippets.

@Medalink
Created March 14, 2019 19:06
Show Gist options
  • Save Medalink/d080de002e559ebe4c80df861debf6b4 to your computer and use it in GitHub Desktop.
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
<?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