PHP - strtoupper() Function
The PHP strtoupper() function is used to convert all alphabetic characters (i.e., a to z) to uppercase in the given string. The term "uppercase" refers to the "capital letter" characters in the alphabet series, such as A, B, C, ... D.
If the given string is already in uppercase, this function will not affect the original string and will remain unchanged.
Syntax
Following is the syntax of the PHP strtoupper() function −
strtoupper(string $str): string
Parameters
This function accepts a single parameter, which is described below −
- string: The input string that needs to be converted to uppercase."
Return Value
This function returns the string with all alphabetic characters converted to uppercase.
Example 1
The following is the basic example of the PHP strtoupper() function −
<?php $str = "tutorialspoint"; echo "The given string: $str"; echo "\nThe string after converting into uppercase: "; #using strtoupper() function echo strtoupper($str); ?>
Output
The above program produces the following output −
The given string: tutorialspoint The string after converting into uppercase: TUTORIALSPOINT
Example 2
Here is another example of using the PHP strtoupper() function. This function converts all alphabetic characters in the given string "hEllO WoRLd!" into uppercase −
<?php $str = "hEllO WoRLd!"; echo "The given string: $str"; echo "\nThe string after converting into uppercase: "; #using strtoupper() function echo strtoupper($str); ?>
Output
Following is the output of the above program −
The given string: hEllO WoRLd! The string after converting into uppercase: HELLO WORLD!
Example 3
If the given string is already in uppercase, the PHP strtoupper() function will not affect the original string, and it will remain unchanged −
<?php $str = "HELLO FROM TP!"; echo "The given string: $str"; echo "\nThe string after converting into uppercase: "; #using strtoupper() function echo strtoupper($str); ?>
Output
After executing the above program, the following output will be displayed −
The given string: HELLO FROM TP! The string after converting into uppercase: HELLO FROM TP!