how to parse html table with php -


i appreciate if give me hint on how parse kind of tables , show results in specific order.

so piece of html have

<table name="maintable" cellspacing="2" cellpadding="3" border="0" id="grid_block" width="100%" class="csm"> <tr class="shade" style="font-weight: bold"> <td width="30%">name</td> <td width="70%">nameone</td> </tr> <tr class="shade" style="font-weight: bold"> <td>date</td> <td>2012-09-30</td> </tr> </table> <br> <table name="maintable" cellspacing=2 cellpadding=3 border=0 id="grid_block" width="100%" class="csm"> <tr> <td colspan="12" align="center" bgcolor="#90ee90"><b>in stock</b></td> </tr> <tr onmouseover="this.classname = 'rowselected';" onmouseout="this.classname = 'shade';"> <td class="greenshade"><b>color/size</b></td> <td align="center" class="greenshade"><b>oo</b></td> <td align="center" class="greenshade"><b>0</b></td> <td align="center" class="greenshade"><b>2</b></td> <td align="center" class="greenshade"><b>4</b></td> <td align="center" class="greenshade"><b>6</b></td> <td align="center" class="greenshade"><b>8</b></td> <td align="center" class="greenshade"><b>10</b></td> <td align="center" class="greenshade"><b>12</b></td> <td align="center" class="greenshade"><b>14</b></td> <td align="center" class="greenshade"><b>16</b></td> <td align="center" class="greenshade"><b>18</b></td> </tr> <tr onmouseover="this.classname = 'rowselected';" onmouseout="this.classname = 'shade';"> <td width='30%' ><b>black</b></td> <td align="center">-</td> <td align="center">-</td> <td align="center">-</td> <td align="center">-</td> <td align="center">-</td> <td align="center">-</td> <td align="center">-</td> <td align="center">-</td> <td align="center">-</td> <td align="center">-</td> <td align="center">-</td> </tr> <tr onmouseover="this.classname = 'rowselected';" onmouseout="this.classname = 'shade';"> <td width='30%' ><b>nude</b></td> <td align="center">-</td> <td align="center">-</td> <td align="center">-</td> <td align="center">-</td> <td align="center">-</td> <td align="center">-</td> <td align="center">-</td> <td align="center">-</td> <td align="center">-</td> <td align="center">-</td> <td align="center">-</td> </tr> 

and problem need parse table , output in form:

;nameone;black;oo;-;

;nameone;black;0;-;

;nameone;black;2;-;

etc.

so - name(from first table), color, size, quantity; every color , size.

i have been trying accomplish last 2 days , no luck far, appreciate help! thank you!

i prefer library https://github.com/olamedia/nokogiri parsing html data. want convert stuff array, here how can this:

$saw = new nokogiri($big_html_string); $my_table = $saw->get('table')->toarray(); 

and after have array attributes , nodes, see print_r($my_table) notice $big_html_string should whole html <html>, <body> tags!


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -