This question already has an answer here:
Extract all heading tags (h1, h2, h3, ...) and it's content. For example :
<h1 id="title">This is the title</h1>
<h2 id="subtitle">This is the subtitle</h2>
<p>And this is the paragraph</p>
Will be extracted as :
<h1 id="title">This is the title</h1>
and <h2 id="subtitle">This is the subtitle</h2>
I'm using PHP and using regex as the title say.
</div>