I'm trying to convert a string of HTML to an array of HTML. For example, I might have a string of arbitrary HTML that looks like this:
"<div>This</div><h1>Is</h1> <p>A</p> <a href="#">Test</a>"
(There may or may not be spaces between the tag elements)
I'm trying to convert it into an array that looks like this:
["<div>This</div>", "<h1>Is</h1>", "<p>A</p>", "<a href="#">Test</a>"]
This is just for displaying the tags as text - I'm not going to use them as HTML elements.
I have looked at this example here, and it almost works except it strips the tags from the inner text: https://stackoverflow.com/a/54340630/1282216
I'm looking for a solution that does not involve DOM parsing - if possible.
Any suggestions welcome!