The strtoupper() Function in PHP
Introduction
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);
}
0
likes
Your Feedback
Help us improve by sharing your thoughts
Online Learner helps developers master programming, database concepts, interview preparation, and real-world implementation through structured learning paths.
Quick Links
© 2023 - 2026 OnlineLearner.in | All Rights Reserved.
