The `strtoupper()` function in PHP converts a string to uppercase. It’s a simple but useful string manipulation function that works the same way in PHP 8.PHP 8.1 PHP 8.2 PHP 8.3 PHP and PHP 8.4 as in previous versions.
Basic Syntax
<?php
strtoupper(string $string): string
?>
Example Usage
<?php
$original = "Hello, World!";
$uppercase = strtoupper($original);
echo $original; // Outputs: Hello, World!
echo $uppercase; // Outputs: HELLO, WORLD!
?>
Multibyte Considerations
<?php
$text = "café à Paris
echo strtoupper($text); // Outputs: CAFé à PARIS (incorrect)
echo mb_strtoupper($text); // Outputs: CAFÉ À PARIS (correct)
?>
Practical Example
<?php
// Case-insensitive comparison
$userInput = "yes";
if (strtoupper($userInput) === "YES") {
echo "User confirmed!";
} else {
echo "User did not confirm.";
}
// Converting database fields for display
$productName = "wireless headphones";
echo "PRODUCT: " . strtoupper($productName);
?>
Remember that `strtoupper()` is locale-dependent, so its behavior might change based on the current locale setting for character classification.# Using `strtoupper()` in PHP 8.2