ed750e2eed61cef299ff6e132cdc8f05ea3f1390.svn-base 940 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. // example of how to use basic selector to retrieve HTML contents
  3. include('../simple_html_dom.php');
  4. // get DOM from URL or file
  5. $html = file_get_html('http://www.google.com/');
  6. // find all link
  7. foreach($html->find('a') as $e)
  8. echo $e->href . '<br>';
  9. // find all image
  10. foreach($html->find('img') as $e)
  11. echo $e->src . '<br>';
  12. // find all image with full tag
  13. foreach($html->find('img') as $e)
  14. echo $e->outertext . '<br>';
  15. // find all div tags with id=gbar
  16. foreach($html->find('div#gbar') as $e)
  17. echo $e->innertext . '<br>';
  18. // find all span tags with class=gb1
  19. foreach($html->find('span.gb1') as $e)
  20. echo $e->outertext . '<br>';
  21. // find all td tags with attribite align=center
  22. foreach($html->find('td[align=center]') as $e)
  23. echo $e->innertext . '<br>';
  24. // extract text from table
  25. echo $html->find('td[align="center"]', 1)->plaintext.'<br><hr>';
  26. // extract text from HTML
  27. echo $html->plaintext;
  28. ?>