<?
/*
Author: Alexey G. Piyanin (e-mail: drdrzlo at mail dot ru)
Date: Feb 15 2005
Title: Page tree
*/
include('SAXParser.php');
function begin($tag,$attributes,$readSize){
global $stack,$t;?>
<table cellspacing="0" cellpadding="0" border="0">
<tr>
<td><?=str_repeat(' ',5*sizeof($stack))?></td>
<td><nobr><b><?=$tag?></b>: <?var_dump($attributes)?></nobr></td>
</tr>
</table>
<?if (!in_array($tag,$t)) array_unshift($stack,$tag);
}
function endTag($tag,$readSize){
global $stack;
while(reset($stack)!=$tag && !empty($stack)) array_shift($stack);
array_shift($stack);?>
<table cellspacing="0" cellpadding="0" border="0">
<tr>
<td><?=str_repeat(' ',5*sizeof($stack))?></td>
<td><nobr><b>/<?=$tag?></b></td>
</tr>
</table>
<?}
function character($str){
global $stack;?>
<table cellspacing="0" cellpadding="0" border="0">
<tr>
<td><?=str_repeat(' ',5*sizeof($stack))?></td>
<td style="border: 1px solid #000000;"><?=htmlspecialchars($str)?><?if (trim($str)==''){?> <?}?></td>
</tr>
</table>
<?
}
$t = array('br','meta','img','spacer','input','base','hr','link',);
$stack = array();
$URL = 'http://yahoo.com';
$parser = new HTML_SAXParser();
$parser->initFunc('begin','endTag','character');?>
<html>
<body>
<center>Source page:<br><iframe src="<?=$URL?>" width="600" height="400" ></iframe><br><br>
Page tree:<br></center>
<?$parser->parse($URL);?>
</body></html>
|