In website development, there is a lot of data that needs to be regular and easy for administrators to manage. Therefore, when submitting requests for some stored data, case requirements are required. However, in order to facilitate user input, we do not deliberately require users to enter uppercase or lowercase letters. Instead, when storing data, program control is used to store the input content in uppercase or lowercase letters. In this chapter, we will show you how to convert the string we input to uppercase or lowercase.
First we learn two functions: strtoupper() function and strtolower() function
Method to convert all strings into uppercase:
strtoupper() function
strtoupper() function converts the string to uppercase. The syntax is as follows:strtoupper (str )
Convert all strings to lowercase:
strtolower() function
strtolower() function is to All strings are converted to lowercase, the syntax is as follows:strtolower (str )
Application example
The following example fills in the user The book numbers in the book information are all stored in uppercase. The code is as follows:图书名称:$name"; echo "字符串大小写转换
编号:$cod
"; echo "价格:$pri
"; echo "数量:$num
"; echo "产地:$pro
"; } ?>Conduct the string Case conversion is not a necessary function and can be selected according to the different requirements of each website. For example, in the backend product addition page of an e-commerce website, in order to display product models with unified specifications, you can use the two case conversion functions explained in this chapter. So it is very necessary to master these two functions. For more questions about strings, please pay attention tophp string stringspecial topic
The above is the detailed content of How to convert string to uppercase and lowercase in php?. For more information, please follow other related articles on the PHP Chinese website!