The ucfirst() function is used to convert the first character of the string into the uppercase. It is an in-built function of PHP, which takes a string as input and converts only the first letter of that string to uppercase. This function converts only the first character of the string to uppercase and others remains unchanged.
Hint: Use the PHP ucfirst()
function
Syntax
ucfirst($string)
Parameters
$string (required): This is a mandatory parameter of this function which specifies a first character of a string into uppercase.
Return Value
It returns converted first character of a string into uppercase.
Example
You can use the PHP ucfirst()
function to convert a first character of a string into uppercase. Let’s check out the following example to understand how this function actually works:
<?php
$my_str = 'learn, share and grow your coding skills';
echo ucfirst($my_str);
?>
Output
Learn, share and grow your coding skills
There are some other functions in PHP which are similar to the ucfirst() function:
Related PHP functions
- strtolower() – It converts a string into lowercase.
- strtoupper() – It converts a string into uppercase.
- lcfirst() – It converts the first character of a string into lowercase.
- ucwords() – It converts the first character of each word in a string into uppercase.