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);
}
At Online Learner, we're on a mission to ignite a passion for learning and empower individuals to reach their full potential. Founded by a team of dedicated educators and industry experts, our platform is designed to provide accessible and engaging educational resources for learners of all ages and backgrounds.
Terms Disclaimer About Us Contact Us
Copyright 2023-2025 © All rights reserved.