I have explained how to convert string uppercase and lowercase letters. However, sometimes we do not need to convert string letters in uppercase or lowercase, however, you only need to convert the first letter of a string in upper or lower case. So today, we will show you how to convert the first letter of a string in upper or lower case. I have explained how to convert string uppercase and lowercase letters. However, sometimes we do not need to convert string letters in uppercase or lowercase, however, you only need to convert the first letter of a string in upper or lower case.
Therefore, this article will help you understand,How to convert the first letter of a string in upper or lower case.
Converts the first letter of a string in uppercase or lowercase as follows:
First, the first letter of each word is converted to uppercase.
Converts the first letter of each word in a string to uppercase. We use the ucwords () function. The syntax is as follows:
ucwords(string)
The string parameter is the string to be converted.
Example
Code running result:
Case 2: convert the first letter of a word to uppercase
Convert the first letter of a word to uppercase. We use the ucfirst () function. The syntax is as follows:
ucfirst(string)
The string parameter is the string to be converted.
Example
Code running result:
The ucfirst () function only converts the first letter of the first word in uppercase, and the subsequent words are not converted.
Case 3: The first letter of a word is converted to lowercase letters.
Convert the first letter of a word to lowercase. We use the lcfirst () function. The syntax is as follows:
lcfirst(string)
The string parameter is the string to be converted.
Example
Code running result:
The lcfirst () function converts the letters of the first word to lowercase, rather than the first letter of each word to lowercase.
Converts the first letter of a string in upper or lower case. how does php convert the string in upper or lower case? The usage is similar. if you are interested, you can check it out.