How does PHP convert the first letter of a string into a case?

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.