PHP 8.4.2 Released!

mb_ucfirst

(PHP 8 >= 8.4.0)

mb_ucfirstMake a string's first character uppercase

Açıklama

mb_ucfirst(string $string, ?string $encoding = null): string

Performs a multi-byte safe ucfirst() operation, and returns a string with the first character of string title-cased.

Bağımsız Değişkenler

string
The input string.
encoding
The string encoding.

Dönen Değerler

Returns the resulting string.

Notlar

Bilginize:

By contrast to the standard case folding functions such as strtolower() and strtoupper(), case folding is performed on the basis of the Unicode character properties. Thus the behaviour of this function is not affected by locale settings and it can convert any characters that have 'alphabetic' property, such a-umlaut (ä).

For more information about the Unicode properties, please see » http://www.unicode.org/reports/tr21/.

Ayrıca Bakınız

  • mb_lcfirst() - Make a string's first character lowercase
  • mb_convert_case() - Bir dizgeye büyük-küçük harf dönüşümü uygular
  • ucfirst() - Dizgenin ilk karakterini büyük harfe çevirir
add a note

User Contributed Notes 1 note

up
1
hans at loltek dot net
1 month ago
polyfill:

<?php
if(PHP_VERSION_ID < 80400) {
function
mb_ucfirst(string $str, string $encoding = null): string
{
if (
$encoding === null) {
$encoding = mb_internal_encoding();
}
return
mb_strtoupper(mb_substr($str, 0, 1, $encoding), $encoding) . mb_substr($str, 1, null, $encoding);
}

}
?>

if you wonder why i bother with mb_internal_encoding: prior to php7, $encoding was not nullable. if your polyfill don't need php5.6 support, you can drop it.
To Top