Tutorialspoint.dev

PHP | IntlChar getBlockCode() Function

The IntlChar::getBlockCode() function is an inbuilt function in PHP which is used to get the Unicode allocation block containing the code point. This function returns the Unicode allocation block that contains the character.

Syntax:

int IntlChar::getBlockCode ( $codepoint )

Parameters: This function accepts single parameter $codepoint which is mandatory. The $codepoint value is an integer values or character, which is encoded as a UTF-8 string.

Return Value: This function returns the block value for $codepoint. Some block value of codepoint are listed below:

  • IntlChar::BLOCK_CODE_BASIC_LATIN
  • IntlChar::BLOCK_CODE_GREEK
  • IntlChar::BLOCK_CODE_MISCELLANEOUS_SYMBOLS

Below programs illustrate the IntlChar::getBlockCode() function in PHP:



Program 1:

<?php
  
// PHP function to illustrate 
// the use of IntlChar::getBlockCode()
  
// Input data is character type
var_dump(IntlChar::getBlockCode("G") === IntlChar::BLOCK_CODE_BASIC_LATIN);
  
// Input data is string type
var_dump(IntlChar::getBlockCode("ABC") === IntlChar::BLOCK_CODE_BASIC_LATIN);
  
// Input data is character type
var_dump(IntlChar::getBlockCode("*") === IntlChar::BLOCK_CODE_GREEK);
  
// Input data is unicode character type
var_dump(IntlChar::getBlockCode("u{2603}") === IntlChar::BLOCK_CODE_MISCELLANEOUS_SYMBOLS);
  
// Input data is character type
var_dump(IntlChar::getBlockCode("@") === IntlChar::BLOCK_CODE_GREEK);
?>

Output:

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

Program 2:

<?php
// PHP code to illustrate getBlockCode()
       
// Declare an array $arr
$arr = array("G", "GeeksforGeeks", "^", "1001", "6", " ");
      
// Loop run for every array element
foreach ($arr as $val){
          
    // Check each element as code point data
    var_dump(IntlChar::getBlockCode($val));
}
?>

Output:

int(1)
NULL
int(1)
NULL
int(1)
int(1)

Related Articles:

Reference: http://php.net/manual/en/intlchar.getblockcode.php



This article is attributed to GeeksforGeeks.org

leave a comment

code

0 Comments

load comments

Subscribe to Our Newsletter