I have this html table:
<tbody> <tr>..</tr> <tr> <td class="tbl_black_n_1">1</td> <td class="tbl_black_n_1" nowrap="" align="center">23/07/14 08:10</td> <td class="tbl_black_n_1"> <img src="http://www.betonews.com/img/SportId389.gif" width="10" height="10" border="0" alt=""> </td> <td class="tbl_black_n_1"></td> <td class="tbl_black_n_1" nowrap="" align="center">BAK WS</td> <td class="tbl_black_n_1" nowrap="" align="right">M. Eguchi</td> <td class="tbl_black_n_1" align="center">-</td> <td class="tbl_black_n_1" nowrap="">Radwanska U. </td> <td class="tbl_black_n_1" align="center" title=" ">1,02</td> <td class="tbl_black_n_1" align="center"> <td class="tbl_black_n_1" align="center" title=" "> </td> <td class="tbl_black_n_1" align="center"> <td class="tbl_black_n_1" align="center" title=" ">55,00</td> <td class="tbl_black_n_1" align="center"> <td class="tbl_black_n_1" align="right">86%</td> <td class="tbl_black_n_1" align="right">-</td> <td class="tbl_black_n_1" align="right">14%</td> <td class="tbl_black_n_1" align="center" title=" ">524.647</td> <td class="tbl_black_n_1" nowrap=""> <a href="popup.asp?tp=2100&lang=en&idm=553759" target="_blank"><img src="http://www.betonews.com//img/i_betfair.gif" width="12" height="10" border="0" alt=""></a> <a href="popup.asp?tp=2110&lang=en&idm=553759" target="_blank"><img src="http://www.betonews.com//img/i_history.gif" width="12" height="10" border="0" alt=""></a> </td> </tr> <tr>..</tr> <tr>..</tr> <tr>..</tr> ... </tbody> There are more than one hundred <tr> structured at the same way, which contain lots of <td>. How can I loop with xpath to store all data in a database? I don't want to get the first <tr>: the query has to begin with the second <tr> (that I have showed).
This is my php code, but I can not go on.. help!
<?php $url = 'http://www.betonews.com/table.asp?tp=2001&lang=en&dd=23&dm=7&dy=2014&df=1&dw=3'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); curl_close($ch); $document = new DOMDocument(); $document->loadHTML($response); $xpath = new DOMXPath($document); $expression = '/html/body/table[2]/tbody/tr/td[2]/table/tbody/tr/td[2]/table/tbody/tr[2]/td/table/tbody/tr/td/table/tbody/tr[3]/td/table/tbody/tr'; $rows = $xpath->query($expression); $results = array(); foreach ($rows as $row) { $result = array(); ??? } This is what I want to be the final result:
[0] => Array ( [date] => 23/07/14 08:10 [image] => http://www.betonews.com/img/SportId389.gif [team1] => M. Eguchi [team2] => Radwanska U. [1] => 1,02 [x] => 0 [2] => 55,00 [1%] => 86% [x%] => 0 [2%] => 14% [total] => 524.647 )