user429620
user429620

Reputation:

Detecting columns in a document (table) via php - Algorithm

Given a table like the one below, what would be the best way to detect the two columns separately?

So what I would need the total colspans for the first column.

What is important to remember is that the nr of columns can change.

In the case of this example, the second column starts at "10 euro" (second row). The first section is equal to 2 colspans. The other section is 5 colspans.

Any (abstract) ideas on how to do this?

enter image description here

Upvotes: 2

Views: 220

Answers (1)

Ja͢ck
Ja͢ck

Reputation: 173642

You must consider the gaps in between the table cells and mark their positions, like this::

0 1 2 3 4     7
0   2 3 4 5 6 7
0 1 2   4 5   7
...
0   2         7

Once you have built an array with above information, you iterate over them and mark the common gap locations:

0   2         7

Since 0 and 7 are both at the edges of your table, you can strip those off. Then you're left with position 2 as the common gap between your rows.

Done :)

Upvotes: 1

Related Questions