Open In App

PHP | IntlChar getBlockCode() Function

Improve
Improve
Like Article
Like
Save
Share
Report

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 a 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
 
// 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
// PHP code to illustrate IntlChar::getBlockCode()
      
// Declare an array $arr
$arr = array("G", "GeeksforGeeks", "^", "1001", "6", "\n");
     
// 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
 



Last Updated : 04 Nov, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads