Strip and remove html body tags


I have read an html file into variable not I need to get the code between the body tags only

for example the following is in the variable

<meta content="text/html; charset=ISO-8859-1"
<h1>Only This Line</h1>
<h2>and this</h2>

I want to keep only this code

<h1>Only This Line</h1>
<h2>and this </h2>

There are many ways of doing this, using regular expressions, extracting from the DOM etc.

However this works:

// create an array of elements
$a = explode('body>', $text );

// grab the 2nd one and chop off the last 
// rememnants of the closing tag </
echo substr($a[1] ,  0 , -2 ) ;

I mean that will work in the example you gave (thanks for posting that) but you will need to find other solutions in case the body tag contains attributes like this for example:

<body style="rhythm_stick" onload="hitMe();">