Simple html parsing with php -


hi using simple_html_dom library parse html

<tr class="even"> <th>yesterday</th> <td class="avg">42.57%</td> <td class="percent"> -0.06% </td> <td class='arrow'> </td> </tr> <tr > <th>7 day</th> <td class="avg">41.79%</td> <td class="percent"> +0.14% </td> <td class='arrow'> </td> </tr> <tr class="even"> <th>1 month</th> <td class="avg">42.10%</td> <td class="percent"> -5.63% </td> <td class='arrow'> </td> </tr> <tr > <th>3 month</th> <td class="avg">44.198%</td> <td class="percent"> -2.28% </td> <td class='arrow'> </td> </tr> 

i need data in separate variables. such average etc... appreciated. thanks

you should able crawl through them such:

<?php     $simplehtmldom = new simple_html_dom();     $simplehtmldom->load($html);     $tablerows = $simplehtmldom->find('tr');      $rows = array();     if (!empty($tablerows)) {         foreach ($tablerows $tablerow) {             $row = array();             $tablecolumns = $tablerow->find('td.avg, td.percent');             if (!empty($tablecolumns)) {                 foreach ($tablecolumns $tablecolumn) {                     $row[$tablecolumn->class] = $tablecolumn->innertext;                 }             }             $rows[] = $row;         }     }     print_r($rows); ?> 

Comments