Encodera

Thanks for reading!

Donate to the site — we work hard for you.

PHP reference

ucfirst

Makes the first letter of a string uppercase.

Available since: PHP 4

Syntax

ucfirst(string $string): string

Parameters

ParameterTypeDescription
$stringstringThe source string.

Return value

stringThe string with its first letter uppercased.

Examples

An ASCII string:

<?php
 
echo ucfirst('hello world');

Output:

Hello world

The function does not change Cyrillic:

<?php
 
echo ucfirst('привет');

Output:

привет

PHP 8.4 adds mb_ucfirst() for any alphabet:

<?php
 
echo mb_ucfirst('привет');

Output:

Привет

Notes

The other letters are left as they are: ucfirst('hELLO') returns HELLO. To capitalise the first letter of every word, use ucwords().

See also

Related recipes

In the tutorial

  • Strings — Working with strings in PHP — quotes, concatenation, length, searching, replacing and multibyte functions.

Thanks for reading!

Donate to the site — we work hard for you.