| 1 |
<?php |
| 2 |
include_once('../simple_html_dom.php'); |
| 3 |
|
| 4 |
// ----------------------------------------------------------------------------- |
| 5 |
// remove HTML comments |
| 6 |
function html_no_comment($url) { |
| 7 |
// create HTML DOM |
| 8 |
$html = file_get_html($url); |
| 9 |
|
| 10 |
// remove all comment elements |
| 11 |
foreach($html->find('comment') as $e) |
| 12 |
$e->outertext = ''; |
| 13 |
|
| 14 |
$ret = $html->save(); |
| 15 |
|
| 16 |
// clean up memory |
| 17 |
$html->clear(); |
| 18 |
unset($html); |
| 19 |
|
| 20 |
return $ret; |
| 21 |
} |
| 22 |
|
| 23 |
// ----------------------------------------------------------------------------- |
| 24 |
// search elements that contains an specific text |
| 25 |
function find_contains($html, $selector, $keyword, $index=-1) { |
| 26 |
$ret = array(); |
| 27 |
foreach ($html->find($selector) as $e) { |
| 28 |
if (strpos($e->innertext, $keyword)!==false) |
| 29 |
$ret[] = $e; |
| 30 |
} |
| 31 |
|
| 32 |
if ($index<0) return $ret; |
| 33 |
return (isset($ret[$index])) ? $ret[$index] : null; |
| 34 |
} |
| 35 |
?> |