How does PHP convert a string to uppercase and lowercase?

Source: Internet
Author: User
Web site development has a lot of data need to be regular, easy for administrators to manage, so, in some storage data submission request, the case is required. However, in order to make user input convenient, do not intentionally require the user to enter uppercase or lowercase, but when the data is stored, the program controls the input of the contents of the uniform uppercase or lowercase storage. This chapter, we will take you to understand, How to convert the string we entered into uppercase or lowercase

First we learn two functions: the Strtoupper () function and the Strtolower () function

Convert the string all to uppercase:

Strtoupper () function

The Strtoupper () function converts a string to uppercase and has the following syntax:

Strtoupper (str)

Parameter str is the converted String

Example

Use the Strtoupper () function to convert the following variable $STR to uppercase, the code is as follows

<?php$str = "Www.Php.cn"; $str = Strtoupper ($STR); Echo $str; >

Code Run Result:

Convert all strings to lowercase methods:

Strtolower () function

The Strtolower () function converts all strings to lowercase, with the following syntax:

Strtolower (str)

Parameter str is the converted String

Example

Use the Strtolower () function to convert the variable $str to lowercase, with the following code:

<?php$str = "WWW.PHP.CN"; $str = Strtolower ($STR); Echo $str; >

Code Run Result:

Application examples

The following example stores the book numbers in the book information that the user fills out in uppercase, with the following code:

<! DOCTYPE html>

Code Run Result:

Case conversion of strings is not a necessary feature and can be used depending on the different requirements of each site. For example, in the background product add page of e-commerce website, in order to make the model of the product display in uniform specification, we can use the two case conversion function explained in this chapter. So it's very necessary to master these two functions. For more questions about strings, follow the PHP string topic

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.