返回介绍

wptexturize_primes()

发布于 2017-09-11 11:19:38 字数 3186 浏览 947 评论 0 收藏 0

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

Implements a logic tree to determine whether or not “7′.” represents seven feet, then converts the special char into either a prime char or a closing quote char.


description


参数

$haystack

(string) (Required) The plain text to be searched.

$needle

(string) (Required) The character to search for such as ' or ".

$prime

(string) (Required) The prime char to use for replacement.

$open_quote

(string) (Required) The opening quote char. Opening quote replacement must be accomplished already.

$close_quote

(string) (Required) The closing quote char to use for replacement.


返回值

(string) The $haystack value after primes and quotes replacements.


源代码

File: wp-includes/formatting.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

更新日志

Versiondescription
4.3.0Introduced.

相关函数

Uses

  • wp-includes/formatting.php: wp_spaces_regexp()

Used By

  • wp-includes/formatting.php: wptexturize()

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文