Login   Register  
PHP Classes
elePHPant
Icontem

File: example3.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Alexey G. Piyanin  >  HTML SAX Parser  >  example3.php  >  Download  
File: example3.php
Role: Example script
Content type: text/plain
Description: Example #3 (find only first image)
Class: HTML SAX Parser
Parse HTML documents using regular expressions
Author: By
Last change:
Date: 9 years ago
Size: 744 bytes
 

Contents

Class file image Download
<?
/*
Author: Alexey G. Piyanin (e-mail: drdrzlo at mail dot ru)
Date:   Feb 15 2005
Title:  Find first image
*/
include('SAXParser.php');

function 
begin($tag,$attributes,$readSize){
  if (
$tag=='img' && isset($attributes['src'])){
    echo 
'<img src="'.$attributes['src'].'" border="0" '.(isset($attributes['width'])?'width="'.$attributes['width'].'"':'').' '.(isset($attributes['height'])?'height="'.$attributes['height'].'"':'').' /><br>'."\n";
    return -
1;
  }
}

$parser = new HTML_SAXParser();
$parser->initFunc('begin');?>
<html>
<body>
<center>Source page:<br><iframe src="example1.html" width="600" height="400" ></iframe><br><br>
First image:<br>
<?$parser->parse('example1.html');?>
</center>
</body></html>