PHP Classes
elePHPant
Icontem

HTML Data Parser: Parse HTML and template files

Recommend this page to a friend!
  Info   View files View files (7)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2008-12-09 (7 years ago) RSS 2.0 feedStarStarStar 54%Total: 3,403 All time: 976 This week: 956Up
Version License Categories
htmldataparser 1.0GNU General Publi...HTML, Templates
Description Author

This package can be used to parse HTML files to extract its structure of tags and data.

There is a class that can parse HTML files and strings and build an array of elements with all the tags and text data that is found.

There is another class that extends the base parser class to parse template files and extract the list of place holder positions denoted by { and } characters.

Picture of Oleksiy Zubovskyy
Name: Oleksiy Zubovskyy <contact>
Classes: 1 package by
Country: Ukraine Ukraine
Age: 41
All time rank: 89516 in Ukraine Ukraine
Week rank: 1469 Down25 in Ukraine Ukraine Down

Details
//////////////////////////////////////////////////////////////////////

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

  Files folder image Files  
File Role Description
Plain text file parser.php Class Jazarsoft HTML Parser
Accessible without login Plain text file README Doc. readme file
Accessible without login Plain text file step2.html Data example html test file
Accessible without login Plain text file template Example Example template
Plain text file templateparser.php Class HTML Template Data Parser
Accessible without login Plain text file test.php Example Test for HTML Template Data Parser
Accessible without login Plain text file tmpl Data Test template file

 Version Control Unique User Downloads Download Rankings  
 0%
Total:3,403
This week:0
All time:976
This week:956Up
 User Ratings  
 
 All time
Utility:83%StarStarStarStarStar
Consistency:75%StarStarStarStar
Documentation:-
Examples:58%StarStarStar
Tests:-
Videos:-
Overall:54%StarStarStar
Rank:1498