php - How to get all td values and put in array -
i have 1 table need read td values , put in array can write database.
table looks this:
<table class="maintable" width="100%"> <tbody> <tr> <th width="100px">client</th> <th width="70px">version</th> <th width="120px">ip</th> <th width="110px">connected</th> <th width="60px">totalecm</th> <th width="90px">acceptedecm</th> <th width="90px">ecmok</th> <th width="50px">ecmtime</th> <th>last used share</th> </tr> <tr> <td class="alt3" colspan="9"> cccam 1 (338)</td> </tr> <tr id="row1" class="alt1" onmouseover="setupdaterow(1)" onmouseout="setupdaterow(0)"> <td> <a href="/cccamclient?id=1">clientname#1</a> </td> <td>cccam 2.0.11<br>419a6380d63b8aec</td> <td><img src="/flag_usa.gif" title="united states"> 63.15.11.121</td> <td class="online">00d 00:08:16<table class="connect_data"> <tbody> <tr> <td>successful login: 1</td> <td>aborted connections: 0</td> <td>total zapping: 0</td> <td>channel freeze: 0</td> </tr> </tbody> </table> </td> <td align="center">0</td> <td> <span style="float: right;">0%</span> </td> <td><span style="float: right;">0%</span></td> <td align="center">-- ms</td> <td> <span style="float:right;"> <img title="disable" src="disable.png" onclick="imgrequest('/cccamclient?action=disable&id=1',this);"> <img title="debug" src="debug.png" onclick="imgrequest('/cccamclient?action=debug&id=1',this);"></span> </td> </tr> <tr id="row2" class="alt2" onmouseover="setupdaterow(2)" onmouseout="setupdaterow(3)"> <td> <a href="/cccamclient?id=2">clientname#2</a> </td> <td>cccam 2.0.11<br>419a6380d63b8aec</td> <td><img src="/flag_at.gif" title="austria"> 69.75.11.121</td> <td class="online">00d 00:08:16<table class="connect_data"> <tbody> <tr> <td>successful login: 1</td> <td>aborted connections: 0</td> <td>total zapping: 0</td> <td>channel freeze: 0</td> </tr> </tbody> </table> </td> <td align="center">0</td> <td> <span style="float: right;">0%</span> </td> <td><span style="float: right;">0%</span></td> <td align="center">-- ms</td> <td> <span style="float:right;"> <img title="disable" src="disable.png" onclick="imgrequest('/cccamclient?action=disable&id=2',this);"> <img title="debug" src="debug.png" onclick="imgrequest('/cccamclient?action=debug&id=1',this);"></span> </td> </tr> </tbody>
so need when echo array this:
array ( [1] => array ( [0] => clientname#1 [1] => cccam 2.0.11 [2] => 419a6380d63b8aec [3] => /flag_usa.gif [4] => united states [5] -> 63.15.11.121 [6] -> 00d 00:08:16 [7] -> successful login: 1 [8] -> aborted connections: 0 [9] -> total zapping: 0 [10]-> channel freeze: 0 [11]-> ) [2] => array ( [0] => clientname#2 [1] => cccam 2.0.11 [2] => 419a6380d63b8aec [3] => /flag_at.gif [4] => austria [5] -> 69.75.11.121 [6] -> 00d 00:08:16 [7] -> successful login: 1 [8] -> aborted connections: 0 [9] -> total zapping: 0 [10]-> channel freeze: 0 [11]-> ) )
how desired results? tried $dom = new domdocument;
not need table array. if 1 give simple code on jsfiddle.
$dom = new domdocument; @$dom->loadhtml(str_replace('<br>', urlencode('<br>'), $html)); $xpath = new domxpath($dom);
untill here code true :) correcting
// set condition attribute id present //else first tr received $rows = $xpath->query('//tr[@id]'); $array_multics = array(); foreach ($rows $row) { $tmp = array(); // select want. if missed something, add xpath foreach ( $xpath->query('.//td/text() | .//td/a/text() | .//td/img/@src', $row) $col) { $value = trim($col->nodevalue); //exclude `-- ms` , many empty values if(!empty($value) && (strpos($value, '-- ms') === false)) // split <br> comes dom `%3cbr%3` foreach (explode('%3cbr%3', $value) $val) $tmp[] = $val; // here want } $array_multics[] = $tmp; }
array indexed number in question.
Comments
Post a Comment