Conversion method: 1. Use the "strtoupper($str)" statement to convert all lowercase letters to uppercase; 2. Use the "ucfirst($str)" statement to convert the first letter to uppercase; 3. Use " ucwords($str)" statement converts the first letter of each word to uppercase.
The operating environment of this tutorial: Windows 7 system, PHP version 7.1, DELL G3 computer
There are three ways to convert lowercase letters to uppercase in php :
strtoupper() Converts the string to uppercase
ucfirst() Converts the first letter of the string to uppercase
ucwords() Converts the first character of each word in the string to uppercase
1) strtoupper
## The #strtoupper() function can convert the letters in the string to uppercase. The syntax format is as follows:strtoupper($str)
<?php $str = "https://www.php.cn/"; $str = strtoupper($str); echo $str; ?>
## The #ucfirst function converts the first letter of a string to uppercase. The syntax format is as follows:
ucfirst($str)
<?php $str = 'hello world!'; $str = ucfirst($str); echo $str.'<br>'; $str2 = 'HELLO WORLD!'; $str2 = ucfirst(strtolower($str2)); echo $str2; ?>
Hello world! Hello world!
3) ucwords
ucwords() function can convert characters The first letter of each word in the string is converted to uppercase, and the grammatical format is as follows:
ucwords($str)
<?php $str = 'hello world!'; $str = ucwords($str); echo $str.'<br>'; $str2 = 'HELLO WORLD!'; $str2 = ucwords(strtolower($str2)); echo $str2.'<br>'; ?>
Hello World! Hello World!
phptraining
The above is the detailed content of How to convert lowercase letters to uppercase in php. For more information, please follow other related articles on the PHP Chinese website!