Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.