<?
 
/*
 
Author: Alexey G. Piyanin (e-mail: drdrzlo at mail dot ru)
 
Date:   Mar 28 2005
 
Title:  Get body tag content
 
*/
 
include('SAXParser.php');
 
 
$beginPos = -1;
 
$endPos = -1;
 
 
function begin($tag,$attributes,$pos,$length){
 
  global $beginPos;
 
  if ($tag=='body' && $beginPos<0) $beginPos = $pos+$length;
 
}
 
 
function endTag($tag,$pos){
 
  global $endPos;
 
  if ($tag=='body' && $endPos<0) $endPos = $pos;
 
}
 
 
$parser = new HTML_SAXParser();
 
$parser->initFunc('begin','endTag');?>
 
<html>
 
<body>
 
<center>Source page:<br><iframe src="example1.html" width="600" height="400" ></iframe></center><br><br>
 
Body content:<br><pre><?
 
$contentHTML = join('',file('example1.html'));
 
$parser->parseString($contentHTML);
 
if ($beginPos>0 && $endPos>0){ // find body tag
 
  $contentHTML = substr($contentHTML,$beginPos,$endPos-$beginPos); // cut body content
 
  echo htmlspecialchars($contentHTML);
 
}
 
?>
 
</pre></body></html>
 
 |