How to Convert String to Uppercase and Lowercase in PHP

Last Updated on May 18, 2021 by Roshan Parihar

In this tutorial, learn how to convert string to uppercase and lowercase using PHP. The short answer is to use the strtoupper() to change string to uppercase and strtolower to make string lowercase.

You can also make the string characters capitalize with all the first letters in capital format. The ucfirst() function is also available to convert first letter of first word to capital if it is small.

Let’s find out with the example given below to learn each method one-by-one.

Convert String to Uppercase Using strtoupper() in PHP

To convert string to uppercase, you can use the strtoupper() function of PHP. The function takes a single argument as the string variable as given below:

Output

WELCOME TO TUTORIALDEEP!

The output given above shows all the letters converted to uppercase.

How to Convert String to Lowercase Using strtolower() in PHP

You can convert all the letters of a string to lowercase. To change all the characters of a string to lowercase, you have to use the strtolower() function. It takes an argument as the string variable as given below:

Output

welcome to tutorialDeep!

The above example shows all the characters of a string converted to lowercase.

Capitalize String Characters Using ucwords() in PHP

Capitalize string is the way of converting the first letters of each word to capital. It is also called as camel-case first character of each word of the string. To convert string characters to capitalize, you have to use the ucwords() function. The function requires a single argument as the string variable as given below:

Output

You Can Easily Convert String Letters To Capital.

You can check the first letters of each word converted into capital.

Change First Letter of String to Capital Using ucfirst() in PHP

In addition to the above all methods, you can also change the first letter of the first word to capital using the ucfirst() function. See the example below to learn the method:

Output

Hello world!

The above example shows the first letter of the first word of string converted to camel-case.

You May Also Like to Read

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.