How to achieve case conversion in php

青灯夜游
Release: 2023-03-15 07:54:01
Original
6873 people have browsed it

Case conversion method: 1. Use strtolower() to convert characters to lowercase; 2. Use strtoupper() to convert characters to uppercase; 3. Use ucfirst() to convert strings Convert the first letter of each word to uppercase; 4. Use ucwords() to convert the first letter of each word in the string to uppercase.

How to achieve case conversion in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

php realizes upper and lower case Conversion function

#1, strtolower() function--convert characters into lowercase

strtolower() function The letters in the string can be converted to lowercase. The syntax format is as follows:

strtolower($string)
Copy after login

Among them, $string is a parameter of string type. This function can convert the letters in the parameter $string to lowercase. , and return the converted string.

Copy after login

How to achieve case conversion in php

2. Use the strtoupper function--convert characters to uppercase

strtoupper() function The letters in the string can be converted to uppercase. The syntax format is as follows:

strtoupper($string)
Copy after login

Among them, $string is a parameter of string type. This function can convert the letters in the parameter $string to uppercase. , and return the converted string.

Copy after login

How to achieve case conversion in php

3. Use the ucfirst() function--convert the first letter to uppercase

The ucfirst function can convert the first letter of the string into uppercase The first letter is converted to uppercase. The syntax format is as follows:

ucfirst($string)
Copy after login

Among them, $string is the string that needs to be converted.

';
    $str2 = 'HELLO WORLD!';
    $str2 = ucfirst(strtolower($str2));
    echo $str2;
?>
Copy after login

How to achieve case conversion in php

4. Use the ucwords() function--convert the first letter of each word to uppercase

ucwords() The function can convert the first letter of each word in the string to uppercase. The syntax format is as follows:

ucwords($string [, $delimiters = "\t\r\n\f\v" ])
Copy after login

Among them, $string is the string that needs to be converted; $delimiters is an optional parameter, used to indicate word separation. Characters, the default are space characters, tab characters, line feed characters, carriage return characters, horizontal lines and vertical lines.

';
    $str2 = 'HELLO WORLD!';
    $str2 = ucwords(strtolower($str2));
    echo $str2;
?>
Copy after login

How to achieve case conversion in php

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to achieve case conversion in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
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 [email protected]
Popular Tutorials
More>
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!