This will your solution for spliting file into 3 section :
<?
$string = "<html><head><title>Test</title></head><body onload='something'><p>This is where my page goes</p></body></html>";
$result = htmlentities($string);
$result = ereg_replace ("\n", "", $result);
$result = ereg_replace (" ", " ", $result);
print "Source File : <br>";
print "==========================================<br>";
print ( $result );
print "<br>==========================================<br>";
print "<br><br>";
$start1 = "<html";
$stop1 = "<body";
$start2 = "<BoDy";
$stop2 = "</bOdY>";
$srtncount = strlen($string);
$pos_1 = $srtncount - strlen(stristr($string,"$start1"));
$pos_2 = (($srtncount - strlen(stristr($string,"$stop1")))+strlen("$stop1")) - $pos_1;
$result = substr($string, $pos_1, $pos_2-5);
//body tag
$new = substr($string,$pos_2-5,$srtncount);
$newsrtncount = strlen($new);
$pos_1 = $newsrtncount - strlen(stristr($new,"<body"));
$pos_2 = (($newsrtncount - strlen(stristr($new,">")))+strlen(">")) - $pos_1;
$newresult = substr($new, $pos_1, $pos_2);
$result = $result.$newresult;
$result = htmlentities($result);
$result = ereg_replace ("\n", "", $result);
$result = ereg_replace (" ", " ", $result);
print " Section First : <br>";
print "=============================================<br>";
print ( $result );
print "<br>=========================================<br>";
print "<br>";
$bodylen = strlen($newresult); //length of body tag
$pos_3 = strlen($string)-strlen(stristr($string,"$start2"))+$bodylen;
$pos_4 = ((strlen($string)-strlen(stristr($string,"$stop2")))+strlen("$stop2")) - $pos_3-strlen("</body>");
$result = substr($string, $pos_3, $pos_4);
$result = htmlentities($result);
$result = ereg_replace ("\n", "", $result);
$result = ereg_replace (" ", " ", $result);
print " Section second : <br>";
print "=============================================<br>";
print ( $result );
print "<br>=========================================<br>";
print "<br>";
$result = substr($string, $pos_3+$pos_4,$srtncount);
$result = htmlentities($result);
$result = ereg_replace ("\n", "", $result);
$result = ereg_replace (" ", " ", $result);
print " Section Third : <br>";
print "==============================================<br>";
print ( $result );
print "<br>==========================================<br>";
print "<br>";
?>
OUT PUT is :
Source File :
<html><head><title>Test</title></head><body onload='something'><p>This is where my page goes</p></body></html>
Section First :
<html><head><title>Test</title></head><body onload='something'>
Section second :
<p>This is where my page goes</p>
Section Third :
</body></html>