PHP 8.5.0 Released!

mb_ucfirst

(PHP 8 >= 8.4.0)

mb_ucfirstRend une chaîne avec la première lettre en majuscule

Description

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

Effectue une opération ucfirst() multi-octets sûre, et renvoie une chaîne avec la première lettre de string avec titre en majuscule.

Liste de paramètres

string
La chaîne d'entrée.
encoding
La chaîne d'encodage.

Valeurs de retour

Renvoie la chaîne de résultat.

Notes

Note:

Contrairement aux fonctions de conversion de casse standard telles que strtolower() et strtoupper(), la conversion de casse est effectuée sur la base des propriétés des caractères Unicode. Ainsi, le comportement de cette fonction n'est pas affecté par les paramètres régionaux, et elle peut convertir tous les caractères ayant la propriété 'alphabétique', comme le tréma sur le "a" (ä).

Pour plus d'informations sur les propriétés Unicode, veuillez consulter » http://www.unicode.org/reports/tr21/.

Voir aussi

add a note

User Contributed Notes 2 notes

up
0
empiredesrtroyer12 at gmail dot com
2 days ago
For non-english words enconded in utf-8 works mb_convert_case  with MB_CASE_TITLE option

mb_convert_case(mb_substr($str, 0, 1), MB_CASE_TITLE) . mb_substr($str, 1);

For a single word 

echo mb_convert_case('çağla', MB_CASE_TITLE);

https://stackoverflow.com/questions/25729900/ucfirst-doesnt-work-on-non-english-characters
up
-1
hans at loltek dot net
1 year 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