mb_ucfirst
Makes the first letter of a string uppercase, aware of multibyte characters.
Syntax
mb_ucfirst(string $string, ?string $encoding = null): stringParameters
| Parameter | Type | Description |
|---|---|---|
| $string | string | The input string. |
| $encoding | ?string | Optional. The encoding. |
Return value
stringThe string with a capital first letter.
Examples
ucfirst() leaves non-ASCII letters alone:
<?php
echo ucfirst('привет'), ' ', mb_ucfirst('привет');Output:
привет ПриветNotes
The function appeared in PHP 8.4. Older versions use mb_strtoupper(mb_substr($s, 0, 1)) . mb_substr($s, 1).
See also
- ucfirst — Makes the first letter of a string uppercase.
- mb_strtoupper — Converts a string to uppercase.
- mb_convert_case — Changes the case of a string, aware of multibyte characters.
In the tutorial
- New in PHP 8.4 — PHP 8.4 features — property hooks, asymmetric visibility, calling a method right after new, and new array functions.