PHP | Función IntlChar charDirection()

La función IntlChar::charDirection() es una función incorporada en PHP que se usa para obtener el valor de categoría bidireccional para un punto de código. Devuelve el valor de categoría bidireccional para el punto de código, que se utiliza en el algoritmo bidireccional Unicode.

Sintaxis:

int IntlChar::charDirection ( $codepoint )

Parámetros: Esta función acepta un solo parámetro $codepoint que es obligatorio. El valor de $codepoint es un carácter o valor entero, que se codifica como una string UTF-8 .

Valor de retorno: esta función devuelve el valor de categoría bidireccional que se enumeran a continuación:

  • 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

Los siguientes programas ilustran la función IntlChar::charDirection() en PHP:

Programa 1:

<?php
  
// PHP code to illustrate IntlChar::charDirection()
// function
  
// Input data is character type
var_dump(IntlChar::charDirection("A") === 
           IntlChar::CHAR_DIRECTION_LEFT_TO_RIGHT);
  
// Input data is unicode character
var_dump(IntlChar::charDirection("\u{05E9}") === 
           IntlChar::CHAR_DIRECTION_RIGHT_TO_LEFT);
  
// Input data is character type
var_dump(IntlChar::charDirection("+") === 
IntlChar::CHAR_DIRECTION_EUROPEAN_NUMBER_SEPARATOR);
  
// Input data is character type
var_dump(IntlChar::charDirection(".") === 
  IntlChar::CHAR_DIRECTION_COMMON_NUMBER_SEPARATOR);
  
// Input data is string type
var_dump(IntlChar::charDirection("ABC") === 
            IntlChar::CHAR_DIRECTION_RIGHT_TO_LEFT);
  
// Input data is character type
var_dump(IntlChar::charDirection("c") === 
            IntlChar::CHAR_DIRECTION_RIGHT_TO_LEFT);
  
// Input data is character type
var_dump(IntlChar::charDirection("O") === 
            IntlChar::CHAR_DIRECTION_LEFT_TO_RIGHT);
?>
Producción:

bool(true)
bool(true)
bool(true)
bool(true)
bool(false)
bool(false)
bool(true)

Programa 2:

<?php
  
// PHP code to illustrate IntlChar::charDirection()
// function
  
// Input data is character type
var_dump(IntlChar::charDirection("A"));
  
// Input data is unicode character
var_dump(IntlChar::charDirection("\u{05E9}"));
  
// Input data is character type
var_dump(IntlChar::charDirection("+"));
  
// Input data is character type
var_dump(IntlChar::charDirection("."));
  
// Input data is string type
var_dump(IntlChar::charDirection("ABC"));
  
// Input data is character type
var_dump(IntlChar::charDirection("c"));
  
// Input data is character type
var_dump(IntlChar::charDirection("O"));
?>
Producción:

int(0)
int(1)
int(3)
int(6)
NULL
int(0)
int(0)

Artículos relacionados:

Referencia: http://php.net/manual/en/intlchar.chardirection.php

Publicación traducida automáticamente

Artículo escrito por Mahadev99 y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *