IntlChar::enumCharTypes

(PHP 7, PHP 8)

IntlChar::enumCharTypes枚举所有代码点及其 Unicode 通用类别

描述

public static IntlChar::enumCharTypes(callable $callback): void

有效地枚举所有代码点及其 Unicode 通用类别。这对于构建数据结构、枚举所有分配的代码点等很有用。

对于具有给定通用类别(“字符类型”)的每个连续代码点范围,都会调用 callback 函数。相邻范围具有不同的类型。Unicode 标准保证类型的数值为 0..31。

参数

callback

将为每个具有相同通用类别的连续代码点范围调用的函数。以下三个参数将传递给它

  • int $start - 范围的起始代码点
  • int $end - 范围的结束代码点
  • int $name - 类别类型(IntlChar::CHAR_CATEGORY_* 常量之一)

返回值

不返回值。

示例

示例 #1 枚举样本代码点范围

<?php
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
...
添加说明

用户贡献说明

此页面没有用户贡献的说明。
To Top