altsel
altsel

Reputation: 11

How to extract content with preg_match_all for specific divs without id or class only

I like to load some data from an external .html file using preg_match_all! Data is stored in a table containing 2000 lines like this:

<DIV STYLE="top:605px; left:252px; width:70px" Class="S8">4:02</DIV>
<DIV STYLE="top:605px; left:287px; width:43px; height:15px" Class="S6"></DIV>
<DIV STYLE="top:605px; left:295px; width:70px" Class="S8">4:55</DIV>
<DIV STYLE="top:325px; left:295px; width:70px" Class="S8">6037</DIV>
<DIV STYLE="top:325px; left:330px; width:43px; height:15px" Class="S6"></DIV>
<DIV STYLE="top:325px; left:338px; width:70px" Class="S8">6040</DIV>

I'm not sure if this is the right way to use preg_match_all but is it possible to search for specific style values ? eg. find all divs with left attribut between 240px and 300px and return inner div data ?

Upvotes: 1

Views: 1471

Answers (1)

Evan
Evan

Reputation: 825

If you use the regex string "/<DIV STYLE=".*?left:(2[4-9][0-9]|300).*?>(.*?)<\/DIV>/", preg_match_all will return an array with three sub arrays. The first will be the whole div. The second will be the left style value. The last one will be the inner html of the div.

Upvotes: 1

Related Questions