phpday 2025 - Call For Papers

mb_ucfirst

(PHP 8 >= 8.4.0)

mb_ucfirstMake a string's first character uppercase

Descrizione

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 capitalized, if that character is an ASCII character in the range from "a" (0x61) to "z" (0x7a).

Elenco dei parametri

string
The input string.
encoding
The string encoding.

Valori restituiti

Returns the resulting string.

Vedere anche:

add a note

User Contributed Notes 1 note

up
1
hans at loltek dot net
15 days 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