I got a html-string in a variable, which looks something like this:
<h1>Title 1</h1>
Introduction
<h2>Chapter 1</h2>
<p>Always just one line</p>
<p class="description">Some more text.</p>
<p class="description">Maybe with multiple lines.</p>
<h2>Chapter 2</h2>
<p>Always just one line</p>
<p class="description">Some more text.</p>
<p class="description">Maybe with multiple lines.</p>
<h1>Title 2</h1>
Introduction
<h2>Chapter 1</h2>
<p>Always just one line</p>
<p class="description">Some more text.</p>
<p class="description">Maybe with multiple lines.</p>
<h2>Chapter 2</h2>
<p>Always just one line</p>
<p class="description">Some more text.</p>
<p class="description">Maybe with multiple lines.</p>
For further processing I need these "blocks" in a variable (array). First of all the main-chapter which starts with a <h1>
and goes to the next <h1>
should be seperated.
I tried to use explode()
with a delimiter <h1
But that removes part of the tag itself.
And as a second step I also need to separate the chapter of each "block". At a last step I need to get the description of a chapter content.
I think the key is the first step: Split the complete thing into main-chapter into an array. After that I can process the "subblocks" in a foreach loop or something else with the same technique (I guess).