Skip to content

Instantly share code, notes, and snippets.

@calevano
Created March 23, 2020 17:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save calevano/1c28d27c27bd0f679ab797d03e682efe to your computer and use it in GitHub Desktop.
Save calevano/1c28d27c27bd0f679ab797d03e682efe to your computer and use it in GitHub Desktop.
Perform a word ucfirst in php with special characters to UTF-8. Example: área to Área
if (!function_exists('mb_ucfirst')) {
/**
* @param $str
* @param string $encoding
* @param bool $lower_str_end
* @return string
*/
function mb_ucfirst($str, $encoding = "UTF-8", $lower_str_end = false)
{
$first_letter = mb_strtoupper(mb_substr($str, 0, 1, $encoding), $encoding);
if ($lower_str_end) {
$str_end = mb_strtolower(mb_substr($str, 1, mb_strlen($str, $encoding), $encoding), $encoding);
} else {
$str_end = mb_substr($str, 1, mb_strlen($str, $encoding), $encoding);
}
$str = $first_letter . $str_end;
return $str;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment