Example 1, convert the first letter of each word to uppercase: ucwords()
-
- $foo = 'hello world!';
- $foo = ucwords($foo); // Hello World!
- $bar = 'HELLO WORLD!';
- $bar = ucwords ($bar); // HELLO WORLD!
- $bar = ucwords(strtolower($bar)); // Hello World!
- ?>
Copy code
Example 2, the first letter of the first word changes Uppercase: ucfirst()
-
- $foo = 'hello world!';
- $foo = ucfirst($foo); // Hello world!
- $bar = 'HELLO WORLD!';
- $bar = ucfirst ($bar); // HELLO WORLD!
- $bar = ucfirst(strtolower($bar)); // Hello world!
- ?>
Copy code
Example 3, the first letter of the first word changes Lowercase: lcfirst()
-
- $foo = 'HelloWorld';
- $foo = lcfirst($foo); // helloWorld
- $bar = 'HELLO WORLD!';
- $bar = lcfirst($bar) ; // hELLO WORLD!
- $bar = lcfirst(strtoupper($bar)); // hELLO WORLD!
- ?>
- Change all letters to uppercase: strtoupper()
- Change all letters to lowercase: strtolower()
Copy Code
The above introduces a total of five English letter case conversion functions, namely ucwords, ucfirst, lcfirst, strtoupper, and strtolower, each with its own use.
|