eval.in

Paste #902210

PHP — PHP 5.6.23, pasted 1 year ago (json)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?
$value = '<table>
    <tbody>
        <tr>
            <td >.....</td>
            <td>....</td>
        </tr>
        <tr>
            <td>....</td>
            <td>.....</td>
        </tr>
    </tbody>
</table>';

$dom = new domDocument;

$dom->loadHTML($value);
$dom->preserveWhiteSpace = false;


foreach($dom->getElementsByTagName ('table') as $table) {
   foreach ($table->getElementsByTagName ('tr') as $tr) {
      foreach ($tr->getElementsByTagName ('td') as $td) {
         echo $td->nodeValue . "\n";  
      }
   }
}

Program Output

.....
....
....
.....

OK (0.016 sec real, 0.019 sec wall, 14 MB, 46 syscalls)

Fork