Current Location: Home> Latest Articles> Understanding PHP IntlChar::charDirection() Function with Examples

Understanding PHP IntlChar::charDirection() Function with Examples

M66 2025-07-20

Overview of IntlChar::charDirection() Function

In PHP, the IntlChar::charDirection() function is used to determine the bidirectional property (text direction) of a given Unicode character. It is part of the IntlChar class, provided by the Internationalization (Intl) extension, which is useful when handling multilingual content and Unicode-aware string operations.

Function Syntax


int IntlChar::charDirection(val)

Parameter

  • val: A UTF-8 encoded character or its corresponding Unicode code point to be evaluated for its text direction.

Return Values

The function returns an integer representing the character's directional category. Possible values include:

  • IntlChar::CHAR_DIRECTION_LEFT_TO_RIGHT
  • IntlChar::CHAR_DIRECTION_RIGHT_TO_LEFT
  • IntlChar::CHAR_DIRECTION_EUROPEAN_NUMBER
  • IntlChar::CHAR_DIRECTION_EUROPEAN_NUMBER_SEPARATOR
  • IntlChar::CHAR_DIRECTION_EUROPEAN_NUMBER_TERMINATOR
  • IntlChar::CHAR_DIRECTION_ARABIC_NUMBER
  • IntlChar::CHAR_DIRECTION_COMMON_NUMBER_SEPARATOR
  • IntlChar::CHAR_DIRECTION_BLOCK_SEPARATOR
  • IntlChar::CHAR_DIRECTION_SEGMENT_SEPARATOR
  • IntlChar::CHAR_DIRECTION_WHITE_SPACE_NEUTRAL
  • IntlChar::CHAR_DIRECTION_OTHER_NEUTRAL
  • IntlChar::CHAR_DIRECTION_LEFT_TO_RIGHT_EMBEDDING
  • IntlChar::CHAR_DIRECTION_LEFT_TO_RIGHT_OVERRIDE
  • IntlChar::CHAR_DIRECTION_RIGHT_TO_LEFT_ARABIC
  • IntlChar::CHAR_DIRECTION_RIGHT_TO_LEFT_EMBEDDING
  • IntlChar::CHAR_DIRECTION_RIGHT_TO_LEFT_OVERRIDE
  • IntlChar::CHAR_DIRECTION_POP_DIRECTIONAL_FORMAT
  • IntlChar::CHAR_DIRECTION_DIR_NON_SPACING_MARK
  • IntlChar::CHAR_DIRECTION_BOUNDARY_NEUTRAL
  • IntlChar::CHAR_DIRECTION_FIRST_STRONG_ISOLATE
  • IntlChar::CHAR_DIRECTION_LEFT_TO_RIGHT_ISOLATE
  • IntlChar::CHAR_DIRECTION_RIGHT_TO_LEFT_ISOLATE
  • IntlChar::CHAR_DIRECTION_POP_DIRECTIONAL_ISOLATE
  • IntlChar::CHAR_DIRECTION_CHAR_DIRECTION_COUNT

Example Usage


<?php
   var_dump(IntlChar::charDirection("-"));
   echo "<br>";
   var_dump(IntlChar::charDirection("*"));
   echo "<br>";
   var_dump(IntlChar::charDirection("kjh"));
   echo "<br>";
   var_dump(IntlChar::charDirection("H"));
?>

Output


int(3)
int(10)
NULL
int(0)

Conclusion

The IntlChar::charDirection() function is a valuable utility when dealing with Unicode text direction, especially in multilingual and internationalized PHP applications. By leveraging this function, developers can better control how text is rendered and aligned based on character properties, ensuring accurate and consistent visual presentation across languages.