", $matches[0] ); } function get_html_split_regex() { static $regex; if ( ! isset( $regex ) ) { $comments = '!' // Start of comment, after the <. . '(?:' // Unroll the loop: Consume everything until --> is found. . '-(?!->)' // Dash not followed by end of comment. . '[^\-]*+' // Consume non-dashes. . ')*+' // Loop possessively. . '(?:-->)?'; // End of comment. If not found, match all input. $cdata = '!\[CDATA\[' // Start of comment, after the <. . '[^\]]*+' // Consume non-]. . '(?:' // Unroll the loop: Consume everything until ]]> is found. . '](?!]>)' // One ] not followed by end of comment. . '[^\]]*+' // Consume non-]. . ')*+' // Loop possessively. . '(?:]]>)?'; // End of comment. If not found, match all input. $escaped = '(?=' // Is the element escaped? . '!--' . '|' . '!\[CDATA\[' . ')' . '(?(?=!-)' // If yes, which type? . $comments . '|' . $cdata . ')'; $regex = '/(' // Capture the entire match. . '<' // Find start of element. . '(?' // Conditional expression follows. . $escaped // Find end of escaped element. . '|' // ... else ... . '[^>]*>?' // Find end of normal element. . ')' . ')/'; } return $regex; } function wp_html_split( $input ) { return preg_split( get_html_split_regex(), $input, -1, PREG_SPLIT_DELIM_CAPTURE ); } function wp_replace_in_html_tags( $haystack, $replace_pairs ) { // Find all elements. $textarr = wp_html_split( $haystack ); $changed = false; // Optimize when searching for one item. if ( 1 === count( $replace_pairs ) ) { // Extract $needle and $replace. foreach ( $replace_pairs as $needle => $replace ); // Loop through delimiters (elements) only. for ( $i = 1, $c = count( $textarr ); $i < $c; $i += 2 ) { if ( false !== strpos( $textarr[$i], $needle ) ) { $textarr[$i] = str_replace( $needle, $replace, $textarr[$i] ); $changed = true; } } } else { // Extract all $needles. $needles = array_keys( $replace_pairs ); // Loop through delimiters (elements) only. for ( $i = 1, $c = count( $textarr ); $i < $c; $i += 2 ) { foreach ( $needles as $needle ) { if ( false !== strpos( $textarr[$i], $needle ) ) { $textarr[$i] = strtr( $textarr[$i], $replace_pairs ); $changed = true; // After one strtr() break out of the foreach loop and look at next element. break; } } } } if ( $changed ) { $haystack = implode( $textarr ); } return $haystack; } function wpautop( $pee, $br = true ) { $pre_tags = array(); if ( trim($pee) === '' ) return ''; // Just to make things a little easier, pad the end. $pee = $pee . "\n"; /* * Pre tags shouldn't be touched by autop. * Replace pre tags with placeholders and bring them back after autop. */ if ( strpos($pee, '
', $pee );
$last_pee = array_pop($pee_parts);
$pee = '';
$i = 0;
foreach ( $pee_parts as $pee_part ) {
$start = strpos($pee_part, '";
$pre_tags[$name] = substr( $pee_part, $start ) . '';
$pee .= substr( $pee_part, 0, $start ) . $name;
$i++;
}
$pee .= $last_pee;
}
// Change multiple