PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sun May 28, 2017 11:28 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Wed Jan 04, 2017 12:28 pm 
Offline
Forum Newbie

Joined: Wed Jan 04, 2017 12:17 pm
Posts: 2
Dear all,
I would like to submit a question to which unfortunately I can not find solution. I will briefly explain my problem.

I would like to populate the database with the data that are present within a table in an html file and if possible
repeat this for each html file, I have about 2000 files to process.

I did extensive research on the internet and found some solutions based on Regex and others through a
extension DOM Parser but neither worked properly.

Unfortunately my situation is a little complex because the html file that contains the table has other
Information that I do not need, or other html tag I have to eliminate and then, unfortunately,
the table structure isn't always the same for all files. Basically I have at least 7-8 kinds of tables
and none of them has header tags <TH>. A sample structure is this:

<Table>
<Tr >
<Td >
TABLE 1 </ td>
</ Tr>
<Tr >
<Td> Column1 </ td>
<Td> Column2 </ td>
<Td> Column3 </ td>
<Td> COLONNA4 </ td>
<Td> COLONNA5 </ td>
<Td> COLONNA6 </ td>
<Td> COLONNA7 </ td>
</ Tr>
<Tr >
<Td >
1 </ td>
<Td> USER 1 </ td>
<Td> M </ td>
<Td> ROME </ td>
<Td> RM </ td>
<Td> 11111111 </ td>
<Td> 22222222 </ td>

</ Tr>
........
</ Table>

That 's just an example because in some files columns are not 7 but a different number with
different names.

Do you think I have a chance with PHP or other tools which may include the ability to extract data
and place them in a SQL table?

My little project is obviously not for commercial purposes, it is non-profit and only for study.

Thank you all for your attention.
Greetings
Willy


Top
 Profile  
 
PostPosted: Wed Jan 04, 2017 2:44 pm 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6243
Location: Montreal, Canada
So the first row can be mapped to the column names and the remaining rows contain the data? Could you not use an XPath query to first build up column names and then create an array of data which you could insert into your database? What have you tried and where did it fall short?

_________________
Supported PHP versions No longer supported versions


Top
 Profile  
 
PostPosted: Thu Jan 05, 2017 8:12 am 
Offline
Forum Newbie

Joined: Wed Jan 04, 2017 12:17 pm
Posts: 2
Celauran wrote:
So the first row can be mapped to the column names and the remaining rows contain the data?

yes

Celauran wrote:
Could you not use an XPath query to first build up column names and then create an array of data which you could insert into your database? What have you tried and where did it fall short?


I tried with regex and DOM using some little php script downloaded from web. If you have more time can you post a little example ?
Thanks
Willy


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group