# _wp_utf8_codepoint_span()

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

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

## Сигнатура

```php
_wp_utf8_codepoint_span( string $text, int $byte_offset, int $max_code_points, ?int $found_code_points ): int
```

## Описание

Участки некорректных байтов считаются одной кодовой точкой согласно правилу максимальной подчасти. Эта функция является резервным методом для вызова strlen( mb_substr( substr( $text, $at ), 0, $max_code_points ) ).

## Параметры

- `$text` `string` — обязательный. Подсчитать количество байтов участка в этом тексте.
- `$byte_offset` `int` — обязательный. Начать подсчёт с этого смещения в байтах.
- `$max_code_points` `int` — обязательный. Прекратить подсчёт после обработки указанного количества кодовых точек или по достижении конца строки.
- `$found_code_points` `?int` — необязательный. Будет установлено в количество найденных кодовых точек в участке, поскольку оно может быть меньше максимального, если строка недостаточно длинная.

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

`int`

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

Файл: `wp-includes/compat-utf8.php:381`

```php
function _wp_utf8_codepoint_span( string $text, int $byte_offset, int $max_code_points, ?int &$found_code_points = 0 ): int {
	$was_at            = $byte_offset;
	$invalid_length    = 0;
	$end               = strlen( $text );
	$found_code_points = 0;

	while ( $byte_offset < $end && $found_code_points < $max_code_points ) {
		$needed      = $max_code_points - $found_code_points;
		$chunk_count = _wp_scan_utf8( $text, $byte_offset, $invalid_length, null, $needed );

		$found_code_points += $chunk_count;

		// Invalid spans only convey one code point count regardless of how long they are.
		if ( 0 !== $invalid_length && $found_code_points < $max_code_points ) {
			++$found_code_points;
			$byte_offset += $invalid_length;
		}
	}

	return $byte_offset - $was_at;
}
```

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

- 6.9.0 — Introduced.

## Связанные

Использует: [`_wp_scan_utf8`](https://chugunov.pro/api-wordpress/functions/_wp_scan_utf8/).

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