Follow
Follow

How to convert the first letter of a string to uppercase in PHP

PHP ucfirst()

The ucfirst() function is used to change the first character of a string to uppercase. Otherwise, We can use the strtolower() function in combination with the ucfirst() function, if you need to make only first letter of the string to uppercase and rest of the string to lowercase.

Syntax

ucfirst(string)

string – This parameter is required. It converts the first character of a string to uppercase.

Example

<?php
$str = 'php tutorials!';
echo ucfirst($str); // Php tutorials!
echo "<br>";
$str1 = 'PHP Tutorials!';
echo ucfirst($str1); // PHP Tutorials!
echo "<br>";
echo ucfirst(strtolower($str1)); // Php tutorials!
?>
Newsletter
Join Design Community
Get the latest updates, creative tips, and exclusive resources straight to your inbox. Let’s explore the future of design and innovation together.