PHP String strtoupper() function

The strtoupper() is one of the most popular functions of PHP, which is widely used to convert the string into uppercase. It takes a string as a parameter and converts all lowercase English character of that string to uppercase. Other characters such as numbers and special characters of the string remain the same. PHP 4+ versions support this function.

Note: The strtoupper () is a binary-safe function.

There are some other functions in PHP which are similar to the strtoupper() function:

Related functions

  • strtolower() - It converts a string into lowercase.
  • lcfirst() - It converts the first character of a string into lowercase.
  • ucfirst() - It converts the first character of a string into uppercase.
  • ucwords() - It converts the first character of each word in a string into uppercase.

Syntax

The syntax for the strtoupper() function is given below, which takes only one string parameter.

Parameters

$string (required): This is a mandatory parameter of this function which specifies a string to convert into uppercase. In simple words - it is a string which is converted into uppercase.

Return Value

It returns converted uppercase string.

Examples

The strtoupper() is a widely used function of PHP. Below some examples are given. With the help of these examples, we can understand the working of this function practically

Example 1

Output:

WELCOME TO JAVATPOINT

Example 2

Output:

String before conversion: hie! I'm Gunjan Garg.
String after conversion: HIE! I'M GUNJAN GARG.

Example 3

In this example, we will see that special characters remain the same after applying strtoupper() function on the string. It only converts alphabet characters, whereas there is no change in special symbols.

Output:

String before conversion: !, @, %, $, and # are the special symbols.
String after conversion: !, @, %, $, AND # ARE THE SPECIAL SYMBOLS.





Latest Courses