PHP 8 reference · String Functions

PHP ucfirst() Function

Make the first character of a string uppercase and leave the rest as it is. Only ASCII letters change.

PHP 8 Since 4.0

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

ucfirst(string $string): string

Parameters

ParameterDescription
string The input string.

Return value

The string with its first character uppercased.

Examples

Capitalize the first letterTry it yourself
<?php
echo ucfirst("hello world"), "\n";
echo ucfirst("iPhone"), "\n";

Output

Hello world
IPhone
Normalize a nameTry it yourself
<?php
$name = "mARY";
echo ucfirst(strtolower($name)), "\n"; // lowercase first for a clean result

Output

Mary

Version history

VersionChange
PHP 4.0Added

In other languages

Was this page helpful?