The strtoupper() function in PHP is used to convert all alphabetic characters in a string to uppercase.
Syntax:
strtoupper(string $string): string
Examples:
1. Basic usage
$text = "hello world";
$uppercaseText = strtoupper($text);
echo $uppercaseText; // Output: HELLO WORLD
2. With mixed case
$text = "Php Is Awesome!";
echo strtoupper($text); // Output: PHP IS AWESOME!
3. User input scenario
$name = "john doe";
echo "Hello, " . strtoupper($name); // Output: Hello, JOHN DOE
Notes:
- It only affects alphabetic characters (a–z, A–Z).
- It does not affect numbers or special characters.
- It works with ASCII characters; for multibyte (UTF-8) strings, use
mb_strtoupper() instead.
Example with form input
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$input = $_POST["username"];
echo "Username in uppercase: " . strtoupper($input);
}