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