PHP Classes

File: readme.php

Recommend this page to a friend!
  Classes of Alexander Zhukov   HTMLSax   readme.php   Download  
File: readme.php
Role: Example script
Content type: text/plain
Description: Example script
Class: HTMLSax
sax-like parser for HTML
Author: By
Last change: added a TODO list
Date: 22 years ago
Size: 1,201 bytes
 

Contents

Class file image Download
<?
/*
    (c) Copyright by Alexander Zhukov alex@veresk.ru. Released under LGPL
    TODO: correct comment handling
*/

include("StateMachine.class.php");
include(
"AttributesParser.class.php");
include(
"HTMLSax.class.php");

// Sample HTML text
$html = "
        <html>
        <head>
        <title>
            my test title
        </title>
        </head>
        <body topmargin=10>
        <h1>A test text</h1>
        example text1
        example text2
        <a href=http://test/?asd>test link</a>
        <img src=\"/images/smile.gif\" width=100 height=100>
        <table width=100% bgcolor=\"black\">
            <tr color=#cceeff>
                <td>cell1</td><td>cell2</td>
            </tr>
        </table>
        </body>
        </html>
        "
;

class
MySax extends HTMLSax
{
    function
MySax()
    {
       
$this->HTMLSax();
       
$this->skipWhitespace = 1; // turn this on if you want to skip whitespace between tags
       
$this->trimDataNodes = 1; // turn this on if you want to trim the data nodes
   
}
   
    function
handle_data($data)
    {
        echo
"data node \"$data\"<br>";
    }

    function
handle_start_tag($tag,$attribs)
    {
        echo
"start tag \"$tag\"<br>";
    }

    function
handle_end_tag($tag)
    {
        echo
"end tag \"$tag\"<br>";
    }

   
}

$p = new MySax();
$p->parse($html);

?>