PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Dave Smith   HTML Parser   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example Usage
Class: HTML Parser
Parse HTML using DOMDocument
Author: By
Last change: Small typo fix in comment
Date: 9 years ago
Size: 1,054 bytes
 

Contents

Class file image Download
<?PHP
error_reporting
(E_ALL ^ E_NOTICE);

//instantiate the class
include('html.parser.class.php');
$parser = new html_parser;

//use this method to load the markup as a file
//comment the line below if you are using the string method

$parser->loadFile('example.html');

//use this method to load the markup as a string
//uncomment both lines to load as a string

//$page = file_get_contents('example.html');
//$parser->loadString($page);

//uncomment the method you want to use to process the markup
//processDocument will parse the entire markup
//processTagName will parse the document for the specified tag name, set option to true to include descendents
//processElementID will parse and return the tag name of the element containing the specified id

$parseResult = $parser->processDocument();
//$parseResult = $parser->processTagName('p',false);
//$parseResult = $parser->processElementID('salesTable');


if( empty($parser->error) ){
    echo
$parser->showResult($parseResult);
}else{
    echo
$parser->error;
}

?>