12b78a92c0f8f965970eacb0c3791a063a37e5ee.svn-base 893 B

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