大网数据广告活动
PHP 语言与运行手册

The Normalizer class

· 52CE 我爱测

(PHP 5 >= 5.3.0, PHP 7, PHP 8, PECL intl >= 1.0.0)

The Normalizer class

(PHP 5 >= 5.3.0, PHP 7, PHP 8, PECL intl >= 1.0.0)

Introduction

Normalization is a process that involves transforming characters and sequences of characters into a formally-defined underlying representation. This process is most important when text needs to be compared for sorting and searching, but it is also used when storing text to ensure that the text is stored in a consistent representation.

The Unicode Consortium has defined a number of normalization forms reflecting the various needs of applications:

  • Normalization Form D (NFD) - Canonical Decomposition
  • Normalization Form C (NFC) - Canonical Decomposition followed by Canonical Composition
  • Normalization Form KD (NFKD) - Compatibility Decomposition
  • Normalization Form KC (NFKC) - Compatibility Decomposition followed by Canonical Composition
The different forms are defined in terms of a set of transformations on the text, transformations that are expressed by both an algorithm and a set of data files.

Class synopsis

class Normalizer {
/* Constants */
public const int FORM_D;
public const int NFD;
public const int FORM_KD;
public const int NFKD;
public const int FORM_C;
public const int NFC;
public const int FORM_KC;
public const int NFKC;
public const int FORM_KC_CF;
public const int NFKC_CF;
/* Methods */
public static function getRawDecomposition(string $string, int $form = Normalizer::FORM_C): ?string
public static function isNormalized(string $string, int $form = Normalizer::FORM_C): bool
public static function normalize(string $string, int $form = Normalizer::FORM_C): string|false
}

Predefined Constants

The following constants define the normalization form used by the normalizer:

Normalizer::FORM_C int

Normalization Form C (NFC) - Canonical Decomposition followed by Canonical Composition

Normalizer::FORM_D int

Normalization Form D (NFD) - Canonical Decomposition

Normalizer::NFD int

Normalizer::FORM_KC int

Normalization Form KC (NFKC) - Compatibility Decomposition, followed by Canonical Composition

Normalizer::NFKC int

Normalizer::FORM_KC_CF int

Normalizer::FORM_KD int

Normalization Form KD (NFKD) - Compatibility Decomposition

Normalizer::NFKD int

Normalizer::NFC int

Normalizer::NFKC_CF int

Changelog

Version Description
8.4.0 The class constants are now typed.
8.0.0 Normalizer::NONE has been removed.

Table of Contents

来源:PHP Documentation Group · 作者与贡献记录 · CC BY 3.0。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
PHP Documentation Group
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。