Home > Article > Backend Development > PHP conversion case tutorial basics
In order to take care of friends who are just learning PHP, this chapter will share with you the most basic knowledge: how to convert upper and lower case in PHP. We will use examples to explain.
strtoupper()
All letters become uppercase
strtolower()
All letters become lowercase
ucwords()
The first letter of each word is converted to uppercase
ucfirst()
The first letter of the first word is converted to uppercase
lcfirst()
The first letter of the first word becomes lowercase
Example:
$foo = 'hello world!'; $foo = ucwords($foo); // Hello World! $bar = 'HELLO WORLD!'; $bar = ucwords($bar); // HELLO WORLD! $bar = ucwords(strtolower($bar)); // Hello World! $foo = 'hello world!'; $foo = ucfirst($foo); // Hello world! $bar = 'HELLO WORLD!'; $bar = ucfirst($bar); // HELLO WORLD! $bar = ucfirst(strtolower($bar)); // Hello world! $foo = 'HelloWorld'; $foo = lcfirst($foo); // helloWorld $bar = 'HELLO WORLD!'; $bar = lcfirst($bar); // hELLO WORLD! $bar = lcfirst(strtoupper($bar)); // hELLO WORLD!
The above content is a detailed explanation of PHP case conversion. I hope this website will be helpful to everyone.
Related recommendations:
How to convert upper and lower case in python
Example of converting the first letter of a string to upper and lower case in php_PHP tutorial
php string first letter conversion to uppercase and lowercase
The above is the detailed content of PHP conversion case tutorial basics. For more information, please follow other related articles on the PHP Chinese website!