<?php
$html = <<<HTML
<p>Some content <a href="www.test.com">A link</a></p>
HTML;
var_export(preg_split('~\s+|(<[^>]+>)~', $html, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE));
- Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
- array (
0 => '<p>',
1 => 'Some',
2 => 'content',
3 => '<a href="www.test.com">',
4 => 'A',
5 => 'link',
6 => '</a>',
7 => '</p>',
)
preferences:
163.79 ms | 408 KiB | 5 Q