This guide will show you how to convert a string to lowercase in PHP using
strtolower() function. This is extremely helpful when you want to manipulate the string quickly to all lowercase characters. You might use this for names, addresses, or even website urls.
In order to make this work we first need to establish a string that we want to make lowercase. Here I create a variable
$myUpperCaseString and have a sentence that is in all uppercase letters.
// This is our all upper case string, that we want converted to lower case $myUpperCaseString = "THIS IS MY, ALL UPPER CASE STRING";
Next we use the
strtolower() function that will lowercase the letters in the string automatically for us. In the below line of code I simply
echo the string that is generated.
// Using strtolower() we convert all of our strings characters to lower case. echo strtolower($myLowerCaseString);
Below is the output from the code we wrote above. You can see that all of the characters are lowercase and it did not impact the comma that was in the string.
this is my, all upper case string
As you can see it was pretty easy to convert the string to lowercase in PHP using the
The full code might look something like below when we put it all together. There are many different use cases for making an entire string lowercase. If you are having troubles or want to share what projects you work on that requires making entire strings lowercase, please drop a comment below!
// This is our all upper case string, that we want converted to lower case $myUpperCaseString = "THIS IS MY ALL UPPER CASE STRING"; // Using strtolower() we convert all of our strings characters to lower case. echo strtolower($myLowerCaseString);