<?php $texts = [ '<p>Some <em>valid</em> HTML</p>', '<p>Some <em invalid</em> HTML</p>', '<p>Some <em data="Element stop>">valid</em> HTML which contains a greater than symbol in a data-attribute</p>', ]; $patterns = [ '/(<.+?>)/is', '/(<[^>]+>)/is', ]; foreach ($texts as $text) { print sprintf('HTML: %s', $text) . PHP_EOL . PHP_EOL; foreach ($patterns as $pattern) { print sprintf('%s', $pattern) . PHP_EOL . PHP_EOL; $chunks = preg_split('/(<.+?>)/is', $text, -1, PREG_SPLIT_DELIM_CAPTURE); var_dump($chunks); print PHP_EOL . PHP_EOL; } }
You have javascript disabled. You will not be able to edit any code.