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);
" which should be "SAME HERE
". Notice the closing slash. You can use this regex: "(.+)
(.+)
" as in your example there is no line break between the "needed test
needed text
" but there is in the piece you do not want. – Mike de Klerk Nov 14 '12 at 13:57What we offer
– screaming SiLENCE Nov 14 '12 at 14:03