Created
March 23, 2020 17:44
-
-
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
This file contains hidden or 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
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