In php, uppercase/lowercase conversion functions include strtolower, strtoupper, ucfirst, and ucwords. This article introduces how to use these functions.
1. Convert string to lowercase
Strtolower (): This function converts all characters of the input string parameter to lowercase, and places the string back in a small form.
The Code is as follows: |
Copy code |
Echo strtolower ("Hello WORLD! "); ?> |
2. Convert characters into uppercase letters
Strtoupper (): this function is opposite to the strtolower function. It converts all characters of the passed character parameter to uppercase and returns the string in uppercase. the usage is the same as that of strtolowe.
The Code is as follows: |
Copy code |
$ Str = "Mary Had A Little Lamb and She LOVED It So "; $ Str = strtoupper ($ str ); Echo $ str; // print MARY HAD A LITTLE LAMB AND SHE LOVED IT SO ?> |
3. Convert the first character of the string to uppercase.
Ucfirst (): This function is used to change the first character of a string to uppercase. This function returns the first character in uppercase. The usage is the same as that of strtolowe.
The Code is as follows: |
Copy code |
$ Foo = 'Hello world! '; $ Foo = ucwords ($ foo); // Hello World! $ Bar = 'Hello WORLD! '; $ Bar = ucwords ($ bar); // hello world! $ Bar = ucwords (strtolower ($ bar); // Hello World! ?> |
4. Convert the first character of each word in the string to uppercase.
Ucwords (): This function converts the first character of each word in the input string to uppercase. for example, "hello world". After this function is processed, "Hello Word" is returned ". the usage is the same as that of strtolowe ().
The Code is as follows: |
Copy code |
$ Foo = 'Hello world! '; $ Foo = ucfirst ($ foo); // Hello world! $ Bar = 'Hello WORLD! '; $ Bar = ucfirst ($ bar); // hello world! $ Bar = ucfirst (strtolower ($ bar); // Hello world! ?> |
5. lowercase lcfirst ()
The Code is as follows: |
Copy code |
$ Foo = 'helloworld '; $ Foo = lcfirst ($ foo); // helloWorld $ Bar = 'Hello WORLD! '; $ Bar = lcfirst ($ bar); // hELLO WORLD! $ Bar = lcfirst (strtoupper ($ bar); // hELLO WORLD! ?> |