What is PHP strtoupper() Function?
If you convert all the characters in a string to uppercase, use PHP strtoupper() function.
Does strtoupper() Function Convert Any Characters to Uppercase?
No. It only converts ASCII alphabetic characters a-z. These are 7-bit characters. Though, these 7 bits are typically stored within a single 8-bit byte and the remaining bit is set to 0. Within these 128 characters, 95 are printable characters. These includes – English letters (A-Z, a-z), digits (0-9), space, and common punctuations and symbols. Actually, the function works on each byte. So, if one byte represents one alphabetic character, it can uppercase that letter.
Characters like other languages (é, ü, ñ, Arabic, Cyrillic, French etc.) are multi byte characters. So, you can’t uppercase those with this strtoupper() function.
Syntax:
strtoupper(string)
Parameters:
The Function has 1 parameter which is required-
string (Required): It specifies a string.
Return Values:
It returns a new string with all letters uppercased.
Examples:
Example 1:
<?php
$string = "schools of web";
echo strtoupper($string);
?>
Output:
SCHOOLS OF WEB
Notes on strtoupper() Function:
- The function doesn’t change the original string. It returns the modified string as a new string.
- It doesn’t affect on numbers and symbols.
- It is a binary-safe string.
- If you want to uppercase a lowercase multi byte characters, use mb_strtoupper() function
PHP Version Support:
PHP 4, PHP 5, PHP 7, PHP 8
Summary: PHP strtoupper() Function
PHP’s strtoupper() function is a built-in string function. Use this function if you want to converts all ASCII alphabetic characters in a string to uppercase.