In php, we can make all characters in a string uppercase easily with the php strtoupper() function.

$variable = "this is a string variable";

echo strtoupper($variable);

//Output:
THIS IS A STRING VARIABLE

When working with string variables in our php programs, it is useful to be able to easily manipulate and change the value of the variables. One such change is if you want to make a string uppercase.

To make all characters in a string uppercase in php, we can use the php strtoupper() function.

strtoupper() takes in a string and converts all characters to uppercase.

Below is a simple example of how to use the strtoupper() function in php to convert a string to uppercase.

$variable = "this is a string variable";

echo strtoupper($variable);

//Output:
THIS IS A STRING VARIABLE

Capitalizing the First Letter of a String in php

If you are looking to just capitalize the first letter of a string, you can use the php ucfirst() function.

ucfirst() capitalizes the first character of a string.

Below is an example of how to use ucfirst() to convert the first character of a string to uppercase.

$variable = "this is a string variable";

echo ucfirst($variable);

//Output:
This is a string variable

Make String Lowercase in php with strtolower()

We can also make a string lowercase easily in php. The strtolower() function takes in a string and makes all of the characters lowercase.

Below is an example of how to make a string lowercase in php with strtolower()

$variable = "THIS IS A STRING VARIABLE";

echo strtolower($variable);

//Output:
this is a string variable

Hopefully this article has been useful for you to learn how to make a string uppercase in php.

Categorized in:

PHP,

Last Update: February 26, 2024