Encodera

Thanks for reading!

Donate to the site — we work hard for you.

PHP reference

mb_ucfirst

Makes the first letter of a string uppercase, aware of multibyte characters.

Syntax

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

Parameters

ParameterTypeDescription
$stringstringThe input string.
$encoding?stringOptional. 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.

Thanks for reading!

Donate to the site — we work hard for you.