# wp_kses_normalize_entities()

URL: https://chugunov.pro/api-wordpress/functions/wp_kses_normalize_entities/
Проверено на WordPress 6.9, обновлено 06.08.2026.
Источник: независимый русскоязычный справочник chugunov.pro. Не является официальной документацией WordPress.

Тип: функция.
Появился в версии: 1.0.0.

## Сигнатура

```php
wp_kses_normalize_entities( string $content, string $context = 'html' ): string
```

## Описание

Нормализует HTML-сущности. Преобразует AT&T в корректное AT&T, : в :, &#XYZZY; в &#XYZZY; и так далее.
Когда $context имеет значение ‘xml’, HTML-сущности преобразуются в их кодовые точки. Например, AT&T…&#XYZZY; преобразуется в AT&T…&#XYZZY;.

## Параметры

- `$content` `string` — обязательный. Содержимое, в котором нужно нормализовать сущности.
- `$context` `string` — необязательный, по умолчанию `'html'`. Контекст нормализации. Может быть либо 'html', либо 'xml'.
  
  Значение по умолчанию — 'html'.

## Возвращаемое значение

`string`

## Исходный код

Файл: `wp-includes/kses.php:2085`

```php
function wp_kses_normalize_entities( $content, $context = 'html' ) {
	// Disarm all entities by converting & to &amp;
	$content = str_replace( '&', '&amp;', $content );

	/*
	 * Decode any character references that are now double-encoded.
	 *
	 * It's important that the following normalizations happen in the correct order.
	 *
	 * At this point, all `&` have been transformed to `&amp;`. Double-encoded named character
	 * references like `&amp;amp;` will be decoded back to their single-encoded form `&amp;`.
	 *
	 * First, numeric (decimal and hexadecimal) character references must be handled so that
	 * `&amp;#09;` becomes `&#9;`. If the named character references were handled first, there
	 * would be no way to know whether the double-encoded character reference had been produced
	 * in this function or was the original input.
	 *
	 * Consider the two examples, first with named entity decoding followed by numeric
	 * entity decoding. We'll use U+002E FULL STOP (.) in our example, this table follows the
	 * string processing from left to right:
	 *
	 * | Input        | &-encoded        | Named ref double-decoded  | Numeric ref double-decoded |
	 * | ------------ | ---------------- | ------------------------- | -------------------------- |
	 * | `&#x2E;`     | `&amp;#x2E;`     | `&amp;#x2E;`              | `&#x2E;`                   |
	 * | `&amp;#x2E;` | `&amp;amp;#x2E;` | `&amp;#x2E;`              | `&#x2E;`                   |
	 *
	 * Notice in the example above that different inputs result in the same result. The second case
	 * was not normalized and produced HTML that is semantically different from the input.
	 *
	 * | Input        | &-encoded        |  Numeric ref double-decoded | Named ref double-decoded |
	 * | ------------ | ---------------- | --------------------------- | ------------------------ |
	 * | `&#x2E;`     | `&amp;#x2E;`     | `&#x2E;`                    | `&#x2E;`                 |
	 * | `&amp;#x2E;` | `&amp;amp;#x2E;` | `&amp;amp;#x2E;`            | `&amp;#x2E;`             |
	 *
	 * Here, each input is normalized to an appropriate output.
	 */
	$content = preg_replace_callback( '/&amp;#(0*[1-9][0-9]{0,6});/', 'wp_kses_normalize_entities2', $content );
	$content = preg_replace_callback( '/&amp;#[Xx](0*[1-9A-Fa-f][0-9A-Fa-f]{0,5});/', 'wp_kses_normalize_entities3', $content );
	if ( 'xml' === $context ) {
		$content = preg_replace_callback( '/&amp;([A-Za-z]{2,8}[0-9]{0,2});/', 'wp_kses_xml_named_entities', $content );
	} else {
		$content = preg_replace_callback( '/&amp;([A-Za-z]{2,8}[0-9]{0,2});/', 'wp_kses_named_entities', $content );
	}

	return $content;
}
```

## История изменений

- 5.5.0 — Added $context parameter.
- 1.0.0 — Introduced.

## Связанные

Используется в: [`esc_url`](https://chugunov.pro/api-wordpress/functions/esc_url/), [`_wp_specialchars`](https://chugunov.pro/api-wordpress/functions/_wp_specialchars/), [`wp_kses`](https://chugunov.pro/api-wordpress/functions/wp_kses/).

Оригинал в официальной документации: https://developer.wordpress.org/reference/functions/wp_kses_normalize_entities/
