fork(1) download
  1. <?php
  2. $html = <<<EOF
  3. <table>
  4. <thead>
  5. <tr>
  6. <th>Col 1</th>
  7. <th>Col 2</th>
  8. <th>Col 3</th>
  9. <th>Col 4</th>
  10. <th>Col 5</th>
  11. <th>Col 6</th>
  12. </tr>
  13. </thead>
  14. <tbody>
  15. <tr>
  16. <td>Conteudo 1</td>
  17. <td>Conteudo 2</td>
  18. <td>Conteudo 3</td>
  19. <td>Conteudo 4</td>
  20. <td>Conteudo 5</td>
  21. <td>Conteudo 6</td>
  22. </tr>
  23. <tr>
  24. <td>Conteudo 1</td>
  25. <td>Conteudo 2</td>
  26. <td>Conteudo 3</td>
  27. <td>Conteudo 4</td>
  28. <td>Conteudo 5</td>
  29. <td>Conteudo 6</td>
  30. </tr>
  31. </tbody>
  32. </table>
  33. EOF;
  34.  
  35.  
  36. // criar um novo documento
  37. $document = new DOMDocument();
  38.  
  39. // ler o html
  40. $document->loadHTML($html);
  41.  
  42. // criar seletor xpath
  43. $selector = new DOMXPath($document);
  44.  
  45. //selecionar conteudo das td's
  46. $results = $selector->query('//td');
  47.  
  48. // resultado
  49. foreach($results as $node) {
  50. echo $node->nodeValue . PHP_EOL;
  51. }
Success #stdin #stdout 0.01s 20568KB
stdin
Standard input is empty
stdout
Conteudo 1
Conteudo 2
Conteudo 3
Conteudo 4
Conteudo 5
Conteudo 6
Conteudo 1
Conteudo 2
Conteudo 3
Conteudo 4
Conteudo 5
Conteudo 6