Login   Register  
PHP Classes
elePHPant
Icontem

File: README

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Oleksiy Zubovskyy  >  HTML Data Parser  >  README  >  Download  
File: README
Role: Documentation
Content type: text/plain
Description: readme file
Class: HTML Data Parser
Parse HTML and template files
Author: By
Last change:
Date: 2008-12-09 07:53
Size: 3,867 bytes
 

Contents

Class file image Download
//////////////////////////////////////////////////////////////////////

HTMLTemplateDataParser_Class - php class for 
extracting data from HTML-source using templates.

/////////////////////////////////////////////////////////////////////


Use syntax below to define a template. Also, please see 
examples (files 'tmpl' and test.php).


Locate a part of HTML code that seems to be a template.
Class uses Jazarsoft HTML Parser to split html source by
tags in the following way below.

230-<td>
231-0017
232-</td>
233-<td>
234-21-дневная очищающая программа.??????? ?????????
235-</td>
236-<td align=middle bgcolor=#FFFFFF>
237-26.00
238-</td>
239-<td align=middle bgcolor=#FFFFFF>
240-17.68
241-</td>


Let's define variables which will be returned in
case template will be found in html source code.

<td>
{{code}}
</td>
<td>
{{name}}
</td>
<td align=middle bgcolor=#FFFFFF>
{{points}}
</td>
<td align=middle bgcolor=#FFFFFF>
{{price}}
</td>

where {{<var name>}}. In this example code, name, points, price - the names
    of variables (see test.php)

Search continues while html code block not found

<td>

</td>
<td>                          

</td>                            
<td align=middle bgcolor=#FFFFFF>

</td>                            
<td align=middle bgcolor=#FFFFFF>

</td>

or while end of file is not reached. If the html template will be found all 
variables code, name, points, price accept values.


In this example table rows have difference by the color we cannot get all 
table rows from the source file 'test.html'. Let's modify template to 
receive all rows  

<td>
{{code}}
</td>
<td>                          
{{name}}
</td>                            
<td align=middle bgcolor={{}}>
{{points}}
</td>                            
<td align=middle bgcolor={{}}>
{{price}}
</td>

where "{{}}" - anything.

338-<td>
339-0338
340-</td>
341-<td>
342-GHD Ежедневный шампунь
343-<img src=/images/pr.gif width=12 height=12 alt='Товар отсутствует на складе'>
344-</td>
345-<td align=middle bgcolor=#FFFFFF>
346-6.00
347-</td>
348-<td align=middle bgcolor=#FFFFFF>
349-5.68
350-</td>


The template differs because of picture 
<img src=/images/pr.gif... 
so, we have to define a new one

<td>
{{code}}
</td>
<td>
{{name}}
<img src=/images/pr.gif {{}} alt='{{text}}'>
</td>
<td align=middle bgcolor={{}}>
{{points}}
</td>
<td align=middle bgcolor={{}}>
{{price}}
</td>

and to join two templates together

<td>
{{code}}
</td>
<td>
{{name}}
</td>
<td align=middle bgcolor={{}}>
{{points}}
</td>
<td align=middle bgcolor={{}}>
{{price}}
</td>
||
<td>
{{code}}
</td>
<td>
{{name}}
<img src=/images/pr.gif {{}} alt='{{text}}'>
</td>
<td align=middle bgcolor={{}}>
{{points}}
</td>
<td align=middle bgcolor={{}}>
{{price}}
</td>

where "||" means "or". The string "<img src=/images/pr.gif {{}}
alt='{{text}}'>" is possible to replace with  "{{}}", if it's not neede 
for you to know whether the image is present. Operator "||" also can be 
used in the template row condition

<td>
{{code}}
</td>
<td>
{{name}}
</td>
<td align=middle bgcolor=#FFFFFF>||<td align=middle bgcolor=#EAF0EF>
{{points}}
</td>
<td align=middle bgcolor=#FFFFFF>||<td align=middle bgcolor=#EAF0EF>
{{price}}
</td>

or

<td>
{{code}}
</td>
<td>
{{name}}
</td>
<td align=middle bgcolor=#FFFFFF>||<td align=middle bgcolor=#EAF0EF>
{{points}}
</td>
<td align=middle bgcolor=#FFFFFF>||<td align=middle bgcolor=#EAF0EF>
{{price}}
</td>
||
<td>
{{code}}
</td>
<td>
{{name}}
<img src=/images/pr.gif {{}} alt='{{text}}'>
</td>
<td align=middle bgcolor=#FFFFFF>||<td align=middle bgcolor=#EAF0EF>
{{points}}
</td>
<td align=middle bgcolor=#FFFFFF>||<td align=middle bgcolor=#EAF0EF>
{{price}}
</td>

See test.php and HTMLTemplateDataParser_Class for more details.


I had no time to test this class properly but it should work fine.
Questions, bugs, comments send to alex.zubovsky@gmail.com