I have HTML data, but I want to get a piece of this data. The top and bottom should be deleted. (everything after the H1 and above a H2 with text ‘What we offer’ should be put in a variable)
<p>This text can be deleted</p>
<h1>This title also</h1>
<h2>FROM THIS TITLE I WANT THE TEXT</h2><p>SAME HERE</p>
<h2>...</h2><p>...</p>
<h2>What we offer</h2>
<p>This text isn't needed</p>
I want all HTML and text beginning AFTER </h1> and ENDING at <h2>What we offer</h2>
Any idea how to do this in PHP?
This does the trick without regexp (Thanks Alexandru), but I’m so curious what regexp I could use to achieve this…
$beginIndex = strpos($htmlString, "</h1>");
$endIndex = strpos($htmlString, "<h2>What we offer</h2>");
$desiredString = substr($htmlString, $beginIndex, $endIndex - $beginIndex);
The regex solution you are requesting would look something like this: