当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


PHP IntlChar enumCharTypes()用法及代码示例


IntlChar::enumCharTypes()函数是PHP中的内置函数,用于提供所有代码点及其Unicode常规类别的目录。所有编目对所有代码点都非常有效。对于枚举所有分配的代码点和构建数据结构等,这将非常有用。对于具有给定常规类别和字符类型的连续范围内的每个代码点,将调用回调函数。相邻范围可以具有不同的类型。 Unicode标准保证类型的数字值为0到31。

用法:

void IntlChar::enumCharTypes( $callback )

参数:该函数接受单个参数$callback。对于具有相同一般类别的每个相邻代码点范围,将调用该函数。回调函数包含以下三个参数:


  • 整数$start:这是起始代码点。
  • 整数$end:这是结束代码点。
  • 整数$name:类别类型(IntlChar::CHAR_CATEGORY_ *常量之一)

返回值:该函数不返回任何值。

以下示例程序旨在说明PHP中的IntlChar::enumCharTypes()函数:

程序:

<?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); 
}); 
  
?>

输出:

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
...

参考: https://www.php.net/manual/en/intlchar.enumchartypes.php



相关用法


注:本文由纯净天空筛选整理自SohomPramanick大神的英文原创作品 PHP | IntlChar enumCharTypes() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。