IntlChar::charMirror() function in PHP

The IntlChar::charMirror() function finds the "mirror-image" character for bidirectional text display. This function is useful when working with text that contains characters like brackets, parentheses, or other symbols that need to be mirrored in right-to-left languages.

Syntax

IntlChar::charMirror(val)

Parameters

  • val − A character or integer value encoded as a UTF-8 string.

Return Value

The IntlChar::charMirror() function returns another Unicode code point that may serve as a mirror-image substitute, or the original codepoint itself if there is no such mapping or the codepoint does not have the Bidi_Mirrored property.

Example

The following example demonstrates how the function mirrors various characters ?

<?php
    var_dump(IntlChar::charMirror("K"));
    echo "<br>";
    var_dump(IntlChar::charMirror("*"));
    echo "<br>";
    var_dump(IntlChar::charMirror("}"));
    echo "<br>";
    var_dump(IntlChar::charMirror("["));
    echo "<br>";
    var_dump(IntlChar::charMirror("("));
    echo "<br>";
?>

Output

The output shows that only certain characters have mirror equivalents ?

string(1) "K"
string(1) "*"
string(1) "{"
string(1) "]"
string(1) ")"

Key Points

Notice that regular letters like "K" and symbols like "*" remain unchanged, while bracket-type characters get mirrored: "}" becomes "{", "[" becomes "]", and "(" becomes ")". This mirroring is essential for proper display of text in bidirectional languages like Arabic or Hebrew.

Conclusion

The IntlChar::charMirror() function is particularly useful for internationalization when working with bidirectional text. It automatically handles the mirroring of appropriate Unicode characters while leaving others unchanged.

Updated on: 2026-03-15T07:45:58+05:30

97 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements