PHP English letter case conversion function
Example 1: convert the initial 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!
- ?>
Example 2: The first letter of a word is capitalized: ucfirst ()
- $ Foo = 'Hello world! ';
- $ Foo = ucfirst ($ foo); // Hello world!
- $ Bar = 'Hello WORLD! ';
- $ Bar = ucfirst ($ bar); // hello world!
- $ Bar = ucfirst (strtolower ($ bar); // Hello world!
- ?>
Example 3: The first letter of a word becomes smaller and written: lcfirst ()
- $ Foo = 'helloworld ';
- $ Foo = lcfirst ($ foo); // helloWorld
- $ Bar = 'Hello WORLD! ';
- $ Bar = lcfirst ($ bar); // hELLO WORLD!
- $ Bar = lcfirst (strtoupper ($ bar); // hELLO WORLD!
- ?>
- Uppercase for all letters: strtoupper ()
- Write down all letters: strtolower ()
The preceding five functions are used to convert uppercase and lowercase letters, including ucwords, ucfirst, lcfirst, strtoupper, and strtolower. |