$string = 'qwe';
$resultString = '';
$stringLength = mb_strlen($string);
if ($stringLength < 2) {
$resultString = mb_strtoupper($string);
} else {
$firstCharacter = mb_substr($string, 0, 1);
$middle = mb_substr($string, 1, $stringLength - 2);
$lastCharacter = mb_substr($string, $stringLength - 1, 1);
$resultString = mb_strtoupper($firstCharacter).$middle.mb_strtoupper($lastCharacter);
}
// кириллица
function custom_mb_ucfirst($str) {
$first = mb_strtoupper(mb_substr($str, 0, 1));
$last = mb_strtoupper(mb_substr($str, -1, 1));
return $first . mb_substr($str, 1, -1) . $last;
}
$str = 'слово';
$str = custom_mb_ucfirst($str);
var_dump($str);
// латиница
$str = 'word';
$str = ucfirst($str);
$str = strrev($str);
$str = ucfirst($str);
$str = strrev($str);
var_dump($str);