WordPress Version: .10
/**
* Separate HTML elements and comments from the text.
*
* @since 4.2.4
*
* @param string $input The text which has to be formatted.
* @return array The formatted text.
*/
function wp_html_split($input)
{
static $regex;
if (!isset($regex)) {
$comments = '!' . '(?:' . '-(?!->)' . '[^\-]*+' . ')*+' . '(?:-->)?';
// End of comment. If not found, match all input.
$cdata = '!\[CDATA\[' . '[^\]]*+' . '(?:' . '](?!]>)' . '[^\]]*+' . ')*+' . '(?:]]>)?';
// End of comment. If not found, match all input.
$regex = '/(' . '<' . '(?(?=!--)' . $comments . '|' . '(?(?=!\[CDATA\[)' . $cdata . '|' . '[^>]*>?' . ')' . ')' . ')/s';
}
return preg_split($regex, $input, -1, PREG_SPLIT_DELIM_CAPTURE);
}