| 1 |
<?php |
| 2 |
include_once('../simple_html_dom.php'); |
| 3 |
|
| 4 |
|
| 5 |
// 1. Write a function with parameter "$element" |
| 6 |
function my_callback($element) { |
| 7 |
if ($element->tag=='input') |
| 8 |
$element->outertext = 'input'; |
| 9 |
|
| 10 |
if ($element->tag=='img') |
| 11 |
$element->outertext = 'img'; |
| 12 |
|
| 13 |
if ($element->tag=='a') |
| 14 |
$element->outertext = 'a'; |
| 15 |
} |
| 16 |
|
| 17 |
|
| 18 |
// 2. create HTML Dom |
| 19 |
$html = file_get_html('http://www.google.com/'); |
| 20 |
|
| 21 |
|
| 22 |
// 3. Register the callback function with it's function name |
| 23 |
$html->set_callback('my_callback'); |
| 24 |
|
| 25 |
|
| 26 |
// 4. Callback function will be invoked while dumping |
| 27 |
echo $html; |
| 28 |
?> |