本文整理汇总了PHP中_get_wptexturize_shortcode_regex函数的典型用法代码示例。如果您正苦于以下问题:PHP _get_wptexturize_shortcode_regex函数的具体用法?PHP _get_wptexturize_shortcode_regex怎么用?PHP _get_wptexturize_shortcode_regex使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_get_wptexturize_shortcode_regex函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: wptexturize
//.........这里部分代码省略.........
$dynamic_replacements['apos'] = array_values($dynamic);
$dynamic = array();
// Quoted Numbers like "42"
if ('"' !== $opening_quote && '"' !== $closing_quote) {
$dynamic['/(?<=\\A|' . $spaces . ')"(\\d[.,\\d]*)"/'] = $open_q_flag . '$1' . $closing_quote;
}
// Double quote at start, or preceded by (, {, <, [, -, or spaces, and not followed by spaces.
if ('"' !== $opening_quote) {
$dynamic['/(?<=\\A|[([{\\-]|<|' . $spaces . ')"(?!' . $spaces . ')/'] = $open_q_flag;
}
$dynamic_characters['quote'] = array_keys($dynamic);
$dynamic_replacements['quote'] = array_values($dynamic);
$dynamic = array();
// Dashes and spaces
$dynamic['/---/'] = $em_dash;
$dynamic['/(?<=^|' . $spaces . ')--(?=$|' . $spaces . ')/'] = $em_dash;
$dynamic['/(?<!xn)--/'] = $en_dash;
$dynamic['/(?<=^|' . $spaces . ')-(?=$|' . $spaces . ')/'] = $en_dash;
$dynamic_characters['dash'] = array_keys($dynamic);
$dynamic_replacements['dash'] = array_values($dynamic);
}
// Must do this every time in case plugins use these filters in a context sensitive manner
/**
* Filter the list of HTML elements not to texturize.
*
* @since 2.8.0
*
* @param array $default_no_texturize_tags An array of HTML element names.
*/
$no_texturize_tags = apply_filters('no_texturize_tags', $default_no_texturize_tags);
/**
* Filter the list of shortcodes not to texturize.
*
* @since 2.8.0
*
* @param array $default_no_texturize_shortcodes An array of shortcode names.
*/
$no_texturize_shortcodes = apply_filters('no_texturize_shortcodes', $default_no_texturize_shortcodes);
$no_texturize_tags_stack = array();
$no_texturize_shortcodes_stack = array();
// Look for shortcodes and HTML elements.
preg_match_all('@\\[/?([^<>&/\\[\\]\\x00-\\x20]++)@', $text, $matches);
$tagnames = array_intersect(array_keys($shortcode_tags), $matches[1]);
$found_shortcodes = !empty($tagnames);
$shortcode_regex = $found_shortcodes ? _get_wptexturize_shortcode_regex($tagnames) : '';
$regex = _get_wptexturize_split_regex($shortcode_regex);
$textarr = preg_split($regex, $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
foreach ($textarr as &$curl) {
// Only call _wptexturize_pushpop_element if $curl is a delimiter.
$first = $curl[0];
if ('<' === $first) {
if ('<!--' === substr($curl, 0, 4)) {
// This is an HTML comment delimiter.
continue;
} else {
// This is an HTML element delimiter.
// Replace each & with & unless it already looks like an entity.
$curl = preg_replace('/&(?!#(?:\\d+|x[a-f0-9]+);|[a-z1-4]{1,8};)/i', '&', $curl);
_wptexturize_pushpop_element($curl, $no_texturize_tags_stack, $no_texturize_tags);
}
} elseif ('' === trim($curl)) {
// This is a newline between delimiters. Performance improves when we check this.
continue;
} elseif ('[' === $first && $found_shortcodes && 1 === preg_match('/^' . $shortcode_regex . '$/', $curl)) {
// This is a shortcode delimiter.
if ('[[' !== substr($curl, 0, 2) && ']]' !== substr($curl, -2)) {
// Looks like a normal shortcode.
_wptexturize_pushpop_element($curl, $no_texturize_shortcodes_stack, $no_texturize_shortcodes);
} else {
// Looks like an escaped shortcode.
continue;
}
} elseif (empty($no_texturize_shortcodes_stack) && empty($no_texturize_tags_stack)) {
// This is neither a delimiter, nor is this content inside of no_texturize pairs. Do texturize.
$curl = str_replace($static_characters, $static_replacements, $curl);
if (false !== strpos($curl, "'")) {
$curl = preg_replace($dynamic_characters['apos'], $dynamic_replacements['apos'], $curl);
$curl = wptexturize_primes($curl, "'", $prime, $open_sq_flag, $closing_single_quote);
$curl = str_replace($apos_flag, $apos, $curl);
$curl = str_replace($open_sq_flag, $opening_single_quote, $curl);
}
if (false !== strpos($curl, '"')) {
$curl = preg_replace($dynamic_characters['quote'], $dynamic_replacements['quote'], $curl);
$curl = wptexturize_primes($curl, '"', $double_prime, $open_q_flag, $closing_quote);
$curl = str_replace($open_q_flag, $opening_quote, $curl);
}
if (false !== strpos($curl, '-')) {
$curl = preg_replace($dynamic_characters['dash'], $dynamic_replacements['dash'], $curl);
}
// 9x9 (times), but never 0x9999
if (1 === preg_match('/(?<=\\d)x\\d/', $curl)) {
// Searching for a digit is 10 times more expensive than for the x, so we avoid doing this one!
$curl = preg_replace('/\\b(\\d(?(?<=0)[\\d\\.,]+|[\\d\\.,]*))x(\\d[\\d\\.,]*)\\b/', '$1×$2', $curl);
}
// Replace each & with & unless it already looks like an entity.
$curl = preg_replace('/&(?!#(?:\\d+|x[a-f0-9]+);|[a-z1-4]{1,8};)/i', '&', $curl);
}
}
return implode('', $textarr);
}
示例2: test_pcre_performance
/**
* Automated performance testing of the main regex.
*
* @dataProvider data_whole_posts
*/
function test_pcre_performance($input)
{
global $shortcode_tags;
// With Shortcodes Disabled
$regex = _get_wptexturize_split_regex();
$result = benchmark_pcre_backtracking($regex, $input, 'split');
$this->assertLessThan(200, $result);
// With Shortcodes Enabled
$shortcode_regex = _get_wptexturize_shortcode_regex(array_keys($shortcode_tags));
$regex = _get_wptexturize_split_regex($shortcode_regex);
$result = benchmark_pcre_backtracking($regex, $input, 'split');
return $this->assertLessThan(200, $result);
}