PHP converts string to lowercase and uppercase. In this tutorial, we will show you, how to convert string to uppercase and how to convert string to lowercase and how to convert the uppercase first letter of each word in PHP with its definition, syntax, parameters, and examples.
1. PHP convert string to lowercase
You can use the php inbuilt function strtolower() for convert string to lowercase.
PHP strtolower() Function
strtolower() is a inbuilt PHP function, which is used to convert string to lowercase.
Note:- This function accept only one parameter as string.
Syntax of this function is:
strtolower( string );
Example for convert 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. PHP convert string to uppercase
You can use the PHP inbuilt function strtoupper() for convert string to uppercase.
PHP strtoupper() Function
strtoupper() is an inbuilt PHP function, which is 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! “