Open In App

PHP | IntlChar enumCharTypes() Function

Last Updated : 27 Aug, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

The IntlChar::enumCharTypes() function is an inbuilt function in PHP which is used to give a catalog of all the code points with their Unicode general categories. All the cataloging happens very efficiently of all the code points. For enumerating all the assigned code points and building data structures etc, this will be very useful. The callback function is called for each code points of a contiguous range with a given general category and the character type. Adjacent ranges could have different types. The guarantee that the numeric value of the type will be 0 to 31 is guaranteed by the Unicode Standard.

Syntax:

void IntlChar::enumCharTypes( $callback )

Parameters: This function accepts single parameter $callback. For each contiguous range of code points with the same general category, the function will be called. The callback function contains three parameters which are listed below:

  • integer $start: It is the starting code point.
  • integer $end: It is the ending code point.
  • integer $name: The category type (one of the IntlChar::CHAR_CATEGORY_* constants)

Return Values: This function does not return any value.

Below program illustrates the IntlChar::enumCharTypes() function in PHP:

Program:




<?php
  
// PHP program to uses IntlChar::enumCharTypes()
// function
IntlChar::enumCharTypes(function($start, $end, $type) {
    printf("U+%04x through U+%04x are in category %d\n",
                                   $start, $end, $type);
});
  
?>


Output:

U+0000 through U+0020 are in category 15
U+0020 through U+0021 are in category 12
U+0021 through U+0024 are in category 23
U+0024 through U+0025 are in category 25
U+0025 through U+0028 are in category 23
U+0028 through U+0029 are in category 20
U+0029 through U+002a are in category 21
U+002a through U+002b are in category 23
U+002b through U+002c are in category 24
U+002c through U+002d are in category 23
U+002d through U+002e are in category 19
U+002e through U+0030 are in category 23
U+0030 through U+003a are in category 9
...

Reference: https://www.php.net/manual/en/intlchar.enumchartypes.php


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads