IntlChar getBlockCode() function in PHP

The IntlChar::getBlockCode() function is used to get the Unicode allocation block containing the specified character value. This function helps identify which Unicode block a character belongs to, such as Basic Latin, Greek, or Miscellaneous Symbols.

Syntax

IntlChar::getBlockCode(mixed $codepoint)

Parameters

  • codepoint − An integer codepoint value (e.g., 0x41 for 'A') or a character encoded as a UTF-8 string (e.g., "A").

Return Value

The function returns an integer representing the Unicode block code constant. Common block codes include ?

  • IntlChar::BLOCK_CODE_BASIC_LATIN − For characters A-Z, a-z, 0-9

  • IntlChar::BLOCK_CODE_GREEK − For Greek alphabet characters

  • IntlChar::BLOCK_CODE_MISCELLANEOUS_SYMBOLS − For various symbols

Example

The following example demonstrates how to get block codes for different characters ?

<?php
    // Check if 'A' belongs to Basic Latin block
    var_dump(IntlChar::getBlockCode("A") === IntlChar::BLOCK_CODE_BASIC_LATIN);
    echo "<br>";
    
    // Check if multi-character string (only first char matters)
    var_dump(IntlChar::getBlockCode("PQRS") === IntlChar::BLOCK_CODE_BASIC_LATIN);
    echo "<br>";
    
    // Check Unicode character using codepoint
    var_dump(IntlChar::getBlockCode(0x2603) === IntlChar::BLOCK_CODE_MISCELLANEOUS_SYMBOLS);
    echo "<br>";
    
    // Display actual block code values
    echo "Block code for 'A': " . IntlChar::getBlockCode("A");
    echo "<br>";
    echo "Block code for Greek Alpha (?): " . IntlChar::getBlockCode(0x03B1);
?>

The output of the above code is ?

bool(true)
bool(true)
bool(true)
Block code for 'A': 1
Block code for Greek Alpha (?): 8

Key Points

  • For multi-character strings, only the first character is processed

  • You can pass either Unicode codepoint integers or UTF-8 strings

  • Block codes are integer constants that identify Unicode character ranges

Conclusion

The IntlChar::getBlockCode() function is useful for Unicode character classification and validation. It returns integer block codes that help identify which Unicode block a character belongs to.

Updated on: 2026-03-15T07:50:07+05:30

72 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements