In this tutorial, we will show you how to convert a string to uppercase and convert a string to lowercase.
PHP String to Uppercase to Lowercase & Lowercase to Uppercase
Here are some ways:
- 1. Convert string to lowercase
- 2. Convert string to uppercase
- 3. PHP uppercase first letter of each word
1. Convert string to lowercase
You can use the php function strtolower() for convert string to lowercase.
PHP strtolower() Function
strtolower() is a built-in PHP function used to convert string to lowercase.
Syntax of this function is:
strtolower( string );
Example for converting string to lowercase:
Let’s take an example, in this example, we have a one-string and we will use the strtolower() function to convert string to lowercase.
<?php // original string $str = "Hello Developers, Have Good Day!"; // convert string to lowercase $res = strtolower($str); echo $res; ?>
The output of the above code is:- ” hello developers, have good day! “
2. Convert string to uppercase
You can use the PHP inbuilt function strtoupper() to convert string to uppercase.
PHP strtoupper() Function
strtoupper() is an inbuilt PHP function used to convert string to strtoupper.
Note:- This function accepts only one parameter as a string.
Syntax of this function is:
strtoupper( string );
Example for convert string to uppercase
Let’s take an example, in this example, we have a one-string and we will use the strtoupper() function to convert string to uppercase.
<?php // original string $str = "hello developers, have good day!"; // convert string to uppercase $res = strtoupper($str); echo $res; ?>
The output of the above code is:- “HELLO DEVELOPERS, HAVE GOOD DAY!”
3. PHP uppercase first letter of each word
You can use the PHP inbuilt function ucwords() for convert uppercase first letter of each word.
PHP ucwords() Function
ucwords() is an inbuilt PHP function, which is used to convert the first letter of each word in a string to uppercase.
Syntax of this function is:
ucwords(string, delimiters);
Example for php uppercase first letter of each word
Let’s take an example, we have a one-string and we will use the ucwords() function to uppercase the first letter of each word.
<?php // original string $str = "hello developers, have good day!"; // convert string to uppercase $res = ucwords($str); echo $res; ?>
The output of the above code is: ” Hello Developers, Have Good Day! “