# wptexturize_primes()

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

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

## Сигнатура

```php
wptexturize_primes( string $haystack, string $needle, string $prime, string $open_quote, string $close_quote ): string
```

## Описание

Реализует дерево логики для определения, обозначает ли «7′.» семь футов, а затем преобразует специальный символ либо в символ штриха, либо в символ закрывающей кавычки.

## Параметры

- `$haystack` `string` — обязательный. Обычный текст для поиска.
- `$needle` `string` — обязательный. Символ для поиска, например ‘ или ".
- `$prime` `string` — обязательный. Символ штриха, используемый для замены.
- `$open_quote` `string` — обязательный. Символ открывающей кавычки. Замена открывающей кавычки уже должна быть выполнена.
- `$close_quote` `string` — обязательный. Символ закрывающей кавычки, используемый для замены.

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

`string`

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

Файл: `wp-includes/formatting.php:320`

```php
function wptexturize_primes( $haystack, $needle, $prime, $open_quote, $close_quote ) {
	$spaces           = wp_spaces_regexp();
	$flag             = '<!--wp-prime-or-quote-->';
	$quote_pattern    = "/$needle(?=\\Z|[.,:;!?)}\\-\\]]|&gt;|" . $spaces . ')/';
	$prime_pattern    = "/(?<=\\d)$needle/";
	$flag_after_digit = "/(?<=\\d)$flag/";
	$flag_no_digit    = "/(?<!\\d)$flag/";

	$sentences = explode( $open_quote, $haystack );

	foreach ( $sentences as $key => &$sentence ) {
		if ( ! str_contains( $sentence, $needle ) ) {
			continue;
		} elseif ( 0 !== $key && 0 === substr_count( $sentence, $close_quote ) ) {
			$sentence = preg_replace( $quote_pattern, $flag, $sentence, -1, $count );
			if ( $count > 1 ) {
				// This sentence appears to have multiple closing quotes. Attempt Vulcan logic.
				$sentence = preg_replace( $flag_no_digit, $close_quote, $sentence, -1, $count2 );
				if ( 0 === $count2 ) {
					// Try looking for a quote followed by a period.
					$count2 = substr_count( $sentence, "$flag." );
					if ( $count2 > 0 ) {
						// Assume the rightmost quote-period match is the end of quotation.
						$pos = strrpos( $sentence, "$flag." );
					} else {
						/*
						 * When all else fails, make the rightmost candidate a closing quote.
						 * This is most likely to be problematic in the context of bug #18549.
						 */
						$pos = strrpos( $sentence, $flag );
					}
					$sentence = substr_replace( $sentence, $close_quote, $pos, strlen( $flag ) );
				}
				// Use conventional replacement on any remaining primes and quotes.
				$sentence = preg_replace( $prime_pattern, $prime, $sentence );
				$sentence = preg_replace( $flag_after_digit, $prime, $sentence );
				$sentence = str_replace( $flag, $close_quote, $sentence );
			} elseif ( 1 === $count ) {
				// Found only one closing quote candidate, so give it priority over primes.
				$sentence = str_replace( $flag, $close_quote, $sentence );
				$sentence = preg_replace( $prime_pattern, $prime, $sentence );
			} else {
				// No closing quotes found. Just run primes pattern.
				$sentence = preg_replace( $prime_pattern, $prime, $sentence );
			}
		} else {
			$sentence = preg_replace( $prime_pattern, $prime, $sentence );
			$sentence = preg_replace( $quote_pattern, $close_quote, $sentence );
		}
		if ( '"' === $needle && str_contains( $sentence, '"' ) ) {
			$sentence = str_replace( '"', $close_quote, $sentence );
		}
	}

	return implode( $open_quote, $sentences );
}
```

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

- 4.3.0 — Introduced.

## Связанные

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

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