Home » PHP ucfirst() Function

PHP ucfirst() Function

by Online Tutorials Library

PHP String ucfirst() Function

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.

Note: PHP 4+ versions support this function.

There are some related functions in PHP which are similar to the strtolower() function:

Related functions

  • strtoupper() – It converts a whole string into uppercase.
  • strtolower() – It converts a whole string into lowercase.
  • lcfirst() – It converts only the first character of a string into lowercase.
  • ucwords() – It converts the first character of each word in a string into uppercase.

Syntax

The syntax of the ucfirst() function is given below that contains only one string parameter.

The ucfirst() returns the converted string.

Parameter

$string (required) – It is a mandatory parameter of this function, which specifies the input string. It is the only argument, passed in the ucfirst() function.

Return Values

The ucfirst() function returns the converted string, where the first character of the string is converted to uppercase.

Examples

There are some examples given, through which we can learn the working of the ucfirst() function. Let’s see the below examples-

Example 1

Output:

As we can see in the below output that the ucfirst() converts only the first character of the string to uppercase.

Hey! myself shivani garg  

Example 2

Output:

Hey! are you Aparna Garg?  No, I'm Gunjan Garg.  

You may also like