实现逻辑树以确定“7”。是否代表7英尺,然后将特殊字符转换为主要字符或结束引号字符。

原型

wptexturize_primes( string $haystack, string $needle, string $prime, string $open_quote, string $close_quote )

参数

$haystack (string) (Required) 要搜索的纯文本。

$needle (string) (Required) 要搜索的字符,例如’或’。

$prime (string) (Required) 用于替换的主要字符。

$open_quote (string) (Required) 开场报价字符。打开报价更换必须已经完成。

$close_quote (string) (Required) 用于替换的结束引号char。

返回值

(string)  素数和引号替换后的$ haystack值。

源文件

路径:wp-includes/formatting.php

<?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 ( false === strpos( $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 && false !== strpos( $sentence, '"' ) ) {
			$sentence = str_replace( '"', $close_quote, $sentence );
		}
	}
	return implode( $open_quote, $sentences );
}
...
?>

其他

英文文档:https://developer.wordpress.org/reference/functions/wptexturize_primes/