How to convert string to uppercase and lowercase in php?

怪我咯
Release: 2023-03-07 17:56:01
Original
5055 people have browsed it

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 )
Copy after login

The parameter str is converted String

Example

Use the strtoupper() function to convert the following variable $str to uppercase. The code is as follows

Copy after login

Code running results:

How to convert string to uppercase and lowercase in php?

Convert all strings to lowercase:

strtolower() function

strtolower() function is to All strings are converted to lowercase, the syntax is as follows:

strtolower (str )
Copy after login

The parameter str is the converted string

Example

Use the strtolower() function to convert the variable $str to lowercase , the code is as follows:

Copy after login

Code running results:

How to convert string to uppercase and lowercase in php?

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

"; } ?>

Copy after login

The code running result:

How to convert string to uppercase and lowercase in php?

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 toHow to convert string to uppercase and lowercase in php?php 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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!