PHP 8 reference · Multibyte String Functions
PHP mb_ucfirst() Function
Make the first character of a string title case, including letters such as é or ı. Added in PHP 8.4.
PHP 8 Since 8.4
Syntax
mb_ucfirst(string $string, ?string $encoding = null): string
Parameters
| Parameter | Description |
|---|---|
string |
The input string. |
encoding optional |
The character encoding; defaults to mb_internal_encoding() (UTF-8). |
Return value
The string with its first character in title case.
Examples
<?php
echo ucfirst("élan"), "\n";
echo mb_ucfirst("élan"), "\n";
Output
élan Élan
Run this on your computer — see “Get Started” for setup.
<?php
echo mb_lcfirst("Ärger"), "\n";
Output
ärger
Run this on your computer — see “Get Started” for setup.
Version history
| Version | Change |
|---|---|
| PHP 8.4 | Added |
In other languages
str.capitalize()· Python
Related
ucfirst()· Make the first character of a string uppercase and leave the rest as it is. Only ASCII letters change.lcfirst()· Make the first character of a string lowercase, leaving the rest unchanged. Handy for turning PascalCase into camelCase.mb_convert_case()· Change the case of a string with Unicode rules: upper, lower, title case or case folding for comparisons.- PHP Strings · tutorial