Data extraction

Hello everyone! I am trying to extract data from a table, but I’d like to use the most efficient way possible. I know I could just keep exploding it and run a foreach, but it seems like there’s probably a more practical way.


<tr>
<td style="border:1px solid #000000;">Data Row</td>
<td style="border:1px solid #000000;" align="right">2-02</td>
<td style="border:1px solid #000000;" align="right">29</td>
<td style="border:1px solid #000000;" align="right">6973</td>
<td style="border:1px solid #000000;" align="right">6966</td>
<td style="border:1px solid #000000;" align="right">2377</td>
<td style="border:1px solid #000000;" align="right">8151</td>
<td style="border:1px solid #000000;" align="right">8151</td>
<td style="border:1px solid #000000;" align="right">0</td>
</tr>

Something like the below would do what you need.

preg_match('/>([0-9-]+)</', $tableData, $matches);

if (sizeof($matches) > 0) {
    echo '<pre>';
    print_r($matches);
    echo '</pre>';
}

preg_match_all(‘~<td.?>(.?)</td>~’, $tableData, $matches);

and then $matches[1] will hold the array of data.

Chris and StarLion, wow. You made it too easy!

Thank you! /bow

…while your at it add a style class definition to the head of your page and get rid of all those repeated style tags :slight_smile: