2024 年日本 PHP 研討會

IntlChar::enumCharTypes

(PHP 7, PHP 8)

IntlChar::enumCharTypes列舉所有具有 Unicode 通用類別的程式碼點

說明

public static IntlChar::enumCharTypes(可呼叫的 $callback):

有效率地列舉所有程式碼點及其 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 到 U+%04x 屬於類別 %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