Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
IntlChar getBidiPairedBracket() function in PHP
The IntlChar::getBidiPairedBracket() function returns the paired bracket character for a given Unicode character. This function is useful when working with bidirectional text processing where you need to find the matching bracket for proper text rendering.
Syntax
IntlChar::getBidiPairedBracket(mixed $codepoint)
Parameters
codepoint − An integer codepoint value or a character encoded as a UTF-8 string.
Return Value
Returns the mapped paired bracket character as a string, or the original character if no paired bracket exists. Returns NULL for invalid input.
Example
The following example demonstrates how to find paired brackets for various characters ?
<?php
// Test with numeric codepoint (no paired bracket)
var_dump(IntlChar::getBidiPairedBracket(15));
echo "<br>";
// Test with opening parenthesis
var_dump(IntlChar::getBidiPairedBracket('('));
echo "<br>";
// Test with opening square bracket
var_dump(IntlChar::getBidiPairedBracket('['));
echo "<br>";
// Test with closing brace
var_dump(IntlChar::getBidiPairedBracket('}'));
echo "<br>";
// Test with regular character (no paired bracket)
var_dump(IntlChar::getBidiPairedBracket('A'));
?>
The output of the above code is ?
int(15)
string(1) ")"
string(1) "]"
string(1) "{"
string(1) "A"
Key Points
The function works with common bracket pairs:
() [] {} <>If the input character is an opening bracket, it returns the corresponding closing bracket
If the input character is a closing bracket, it returns the corresponding opening bracket
For characters that are not brackets, the function returns the original character
Conclusion
The IntlChar::getBidiPairedBracket() function is essential for Unicode text processing, particularly when handling bidirectional text that contains bracket characters. It helps maintain proper bracket pairing in complex text layouts.
