Open In App

PHP | IntlChar charType() Function

The IntlChar::charType() function is an inbuilt function in PHP which is used to get the general category value for a code point. This function returns the general category value for the code point.

Syntax:



int IntlChar::charType ( $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 general category content which are listed below:



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

Program 1:




<?php
  
// PHP code to illustrate IntlChar::charType()
// function
  
// Input data is character type
var_dump(IntlChar::charType("A") === 
  IntlChar::CHAR_CATEGORY_UPPERCASE_LETTER);
  
// Input data is character type
var_dump(IntlChar::charType(".") === 
 IntlChar::CHAR_CATEGORY_OTHER_PUNCTUATION);
  
// Input data is character type
var_dump(IntlChar::charType("\t") === 
      IntlChar::CHAR_CATEGORY_CONTROL_CHAR);
  
// Input data is unicode character
var_dump(IntlChar::charType("\u{2603}") === 
      IntlChar::CHAR_CATEGORY_OTHER_SYMBOL);
  
// Input data is string type
var_dump(IntlChar::charType("ABC") === 
 IntlChar::CHAR_CATEGORY_OTHER_PUNCTUATION);
  
// Input data is character type
var_dump(IntlChar::charType("\n") === 
      IntlChar::CHAR_CATEGORY_CONTROL_CHAR);
?>

Output:
bool(true)
bool(true)
bool(true)
bool(true)
bool(false)
bool(true)

Program 2:




<?php
  
// PHP code to illustrate IntlChar::charType()
// function
  
// Input data is character type
var_dump(IntlChar::charType("A"));
  
// Input data is character type
var_dump(IntlChar::charType("."));
  
// Input data is character type
var_dump(IntlChar::charType("\t"));
  
// Input data is unicode character
var_dump(IntlChar::charType("\u{2603}"));
  
// Input data is string type
var_dump(IntlChar::charType("ABC"));
  
// Input data is character type
var_dump(IntlChar::charType("\n"));
?>

Output:
int(1)
int(23)
int(15)
int(27)
NULL
int(15)

Related Articles:

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


Article Tags :