Recommend this page to a friend! |
Download .zip |
Info | View files (7) | Download .zip | Reputation | Support forum | Blog | Links |
Last Updated | Ratings | Unique User Downloads | Download Rankings | |||||
2008-12-09 (7 years ago) | 54% | Total: 3,404 | All time: 979 This week: 867 |
Version | License | Categories | ||||
htmldataparser 1.0 | GNU General Publi... | HTML, Templates |
Description | Author | |||||||||||||
This package can be used to parse HTML files to extract its structure of tags and data. |
|
////////////////////////////////////////////////////////////////////// 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 |
File | Role | Description |
---|---|---|
parser.php | Class | Jazarsoft HTML Parser |
README | Doc. | readme file |
step2.html | Data | example html test file |
template | Example | Example template |
templateparser.php | Class | HTML Template Data Parser |
test.php | Example | Test for HTML Template Data Parser |
tmpl | Data | Test template file |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
0% |
|
|
User Ratings | ||||||||||||||||||||||||||||||
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.