In php, if we want to convert the characters into uppercase and lowercase letters, use strtolower or strtoupper directly, but to convert the first letter into uppercase and lowercase letters, we need to use ucwords related functions.
Uppercase letters: ucwords ()
The Code is as follows: |
Copy code |
<? Php $ Foo = 'Hello world! '; $ Foo = ucwords ($ foo); // Hello World! $ Bar = 'Hello WORLD! '; $ Bar = ucwords ($ bar); // hello world! $ Bar = ucwords (strtolower ($ bar); // Hello World! ?> |
The first letter is capitalized: ucfirst ()
The Code is as follows: |
Copy code |
<? Php $ Foo = 'Hello world! '; $ Foo = ucfirst ($ foo); // Hello world! $ Bar = 'Hello WORLD! '; $ Bar = ucfirst ($ bar); // hello world! $ Bar = ucfirst (strtolower ($ bar); // Hello world! ?> |
Lowercase lcfirst ()
The Code is as follows: |
Copy code |
<? Php $ Foo = 'helloworld '; $ Foo = lcfirst ($ foo); // helloWorld $ Bar = 'Hello WORLD! '; |