PHP Conference Japan 2024

Normalizer::getRawDecomposition

normalizer_get_raw_decomposition

(PHP 7 >= 7.3, PHP 8)

Normalizer::getRawDecomposition -- normalizer_get_raw_decomposition取得給定 UTF-8 編碼碼位的 Decomposition_Mapping 屬性

說明

物件導向風格

public static Normalizer::getRawDecomposition(字串 $string, 整數 $form = Normalizer::FORM_C): ?字串

程序式風格

normalizer_get_raw_decomposition(字串 $string, 整數 $form = Normalizer::FORM_C): ?字串

取得給定 UTF-8 編碼碼位的「分解映射 (Decomposition_Mapping)」屬性,如同 Unicode 字元資料庫 (UCD) 中所指定。

參數

字串

輸入字串,應為單個 UTF-8 編碼的碼位。

傳回值

如果 UCD 中存在「分解映射」屬性,則傳回包含該屬性的字串

如果該字元沒有「分解映射」屬性,則傳回 null

範例

範例 #1 Normalizer::getRawDecomposition() 範例

<?php

$result
= "";
$strings = [
"a",
"\u{FFDA}",
"\u{FDFA}",
"",
"aa",
"\xF5",
];

foreach (
$strings as $string) {
$decomposition = Normalizer::getRawDecomposition($string);
// $decomposition = normalizer_get_raw_decomposition($string); 程序式寫法

$error_code = intl_get_error_code();
$error_message = intl_get_error_message();

$string_hex = bin2hex($string);
$result .= "---------------------\n";

if (
$decomposition === null) {
$result .= "'$string_hex' 沒有對應的分解映射\n" ;
} else {
$result .= "'$string_hex' 的分解映射為 '" . bin2hex($decomposition) . "'\n" ;
}

$result .= "錯誤資訊: '$error_message' ($error_code)\n";
}

echo
$result;
?>

以上範例將輸出

---------------------
'61' has no decomposition mapping
error info: 'U_ZERO_ERROR' (0)
---------------------
'efbf9a' has the decomposition mapping 'e385a1'
error info: 'U_ZERO_ERROR' (0)
---------------------
'efb7ba' has the decomposition mapping 'd8b5d984d98920d8a7d984d984d98720d8b9d984d98ad98720d988d8b3d984d985'
error info: 'U_ZERO_ERROR' (0)
---------------------
'' has no decomposition mapping
error info: 'Input string must be exactly one UTF-8 encoded code point long.: U_ILLEGAL_ARGUMENT_ERROR' (1)
---------------------
'6161' has no decomposition mapping
error info: 'Input string must be exactly one UTF-8 encoded code point long.: U_ILLEGAL_ARGUMENT_ERROR' (1)
---------------------
'f5' has no decomposition mapping
error info: 'Code point out of range: U_ILLEGAL_ARGUMENT_ERROR' (1)

另請參閱

新增註釋

使用者提供的註釋

此頁面沒有使用者提供的註釋。
To Top