IntlChar toupper() function in PHP

The IntlChar::toupper() function converts a character to its Unicode uppercase equivalent. It works with single characters and returns the uppercase version if available.

Syntax

IntlChar::toupper($val)

Parameters

  • $val − An integer or character encoded as a UTF-8 string. Must be a single character.

Return Value

The function returns the converted uppercase character as a string. If the character is already uppercase or has no uppercase equivalent, the same character is returned. Returns NULL for invalid input.

Example

The following example demonstrates converting characters to uppercase ?

<?php
    var_dump(IntlChar::toupper("j"));
    echo "<br>";
    var_dump(IntlChar::toupper("89"));
    echo "<br>";
    var_dump(IntlChar::toupper("J"));
    echo "<br>";
    var_dump(IntlChar::toupper("jkl"));
    echo "<br>";
    var_dump(IntlChar::toupper("ñ"));
?>

The output of the above code is ?

string(1) "J"
NULL
string(1) "J"
NULL
string(2) "Ñ"

Key Points

  • Only single characters are processed; multi-character strings return NULL

  • Numbers and symbols return NULL as they don't have uppercase equivalents

  • Unicode characters like "ñ" are properly handled

  • Already uppercase characters remain unchanged

Conclusion

The IntlChar::toupper() function provides Unicode-aware uppercase conversion for single characters. It returns NULL for invalid inputs like numbers or multi-character strings.

Updated on: 2026-03-15T07:48:57+05:30

90 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements