What is ucfirst() in PHP?

The ucfirst() function in PHP converts the first character of a string to uppercase.

The figure below shows a visual representation of the ucfirst() function.

Figure 1: Visual representation of ucfirst() function

Syntax

ucfirst(string $string): string

Parameters

The ucfirst() function requires a string whose first character is to be converted to uppercase.

Return value

The ucfirst() function returns the input string, with the first character changed to uppercase and the rest of the string unchanged.

Code

The code below shows how the ucfirst() function works.

<?php
#string
echo("ucfirst('educative'): ");
echo (ucfirst('educative'));
echo("\n");
#string with number
echo("ucfirst('educaTive09'): ");
echo (ucfirst('educaTive09'));
?>
New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources