Before we tell you how to convert the case of a string, there are times when we don't need to completely capitalize or lowercase the letter of the string, but just need to convert the first letter of the string to uppercase or lowercase.
So, this article will show you how to convert the first letter of a string to uppercase or lowercase.
Uppercase or lowercase conversions of the first letter of a string are in the following cases:
First: the first letter of each word is converted to upper case
To convert the first letter of each word of a string to uppercase, we use: Ucwords () function, the syntax is as follows:
Ucwords (String)
Argument string is the string to be converted
Example
<?phpecho ucwords ("Hello World");? >
Code Run Result:
Second case: Converting the first letter to uppercase
To convert the first letter to uppercase, we use the: Ucfirst () function with the following syntax:
Ucfirst (String)
Argument string is the string to be converted
Example
<?phpecho ucfirst ("php hello!");? >
Code Run Result:
The Ucfirst () function converts only the first letter of a word into uppercase, and the subsequent word is not converted.
Third case: First letter converted to lowercase
To convert the first letter to lowercase, we use the: Lcfirst () function with the following syntax:
Lcfirst (String)
Argument string is the string to be converted
Example
<?phpecho Lcfirst ("Php hello!");? >
Code Run Result:
The Lcfirst () function converts the letter of the first word to lowercase, not the first letter of each word to lowercase
Convert the first letter of a string to uppercase or lowercase, followed by how PHP will convert the string to a case? The usage is similar and interested can go to see.
"Recommended"
1. Featured: PHP string
2. Video tutorial: "Php.cn lonely Nine Cheap (4)-php video Tutorial"
3. PHP real-Combat video tutorial