I'm scraping a page with table contents like such:
<table border="1" style="width:100%;" cellspacing="0" cellpadding="3">
<tr class="stats-section">
<td colspan="99">Scoring</td>
</tr>
<tr class="stats-section">
<td colspan="99">2nd Period</td>
</tr>
<tr class="hscore">
<td>UMD</td>
<td>4×4</td>
<td>
Kobe Roth (1)</td>
<td> Noah Cates, Casey Gilling </td>
<td align="right">12:35</td>
</tr>
<tr class="vscore">
<td>BSU</td>
<td>4×4</td>
<td>
Alex Ierullo (1)</td>
<td> Kyle Looft </td>
<td align="right">13:06</td>
</tr>
<tr class="stats-section">
<td colspan="99">3rd Period</td>
</tr>
<tr class="hscore">
<td>UMD</td>
<td></td>
<td>
Blake Biondi (1)</td>
<td> Quinn Olson </td>
<td align="right">10:10</td>
</tr>
</table>
I want to match the <tr class="hscore" AND the <tr class="vscore and change them into the following:
<tr class="hscore">
<td>#1 UMD</td> <!--added #1 -->
...
<tr class="vscore">
<td>#2 BSU</td> <!-- added #2 -->
...
</tr></table>
I don't know what order, or even how many of each hscore or vscore entries there will be. I need to auto increment a variable ($i++;) upon each match to echo the #1 and #2. Is regex my best bet? Maybe str_replace or is Simple Dom and a foreach of each better?
I can't think of a way to add to the $i variable on each match.