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