# searchpro/1.9.3/simplehtmldom/example/simple_html_dom_utility.php

BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS &amp; JavaScript, version 1.9.3. 35 lines.

- Page: https://pluginprobe.com/plugins/searchpro/1.9.3/code/simplehtmldom/example/simple_html_dom_utility.php
- Raw: https://pluginprobe.com/plugins/searchpro/1.9.3/raw/simplehtmldom/example/simple_html_dom_utility.php
- Modified: 2024-08-20T18:00:30+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/searchpro/1.9.3/code/simplehtmldom/example/simple_html_dom_utility.php#L10-L20`.

```php
<?php
include_once('../simple_html_dom.php');

// -----------------------------------------------------------------------------
// remove HTML comments
function html_no_comment($url) {
    // create HTML DOM
    $html = file_get_html($url);

    // remove all comment elements
    foreach($html->find('comment') as $e)
        $e->outertext = '';

    $ret = $html->save();

    // clean up memory
    $html->clear();
    unset($html);

    return $ret;
}

// -----------------------------------------------------------------------------
// search elements that contains an specific text
function find_contains($html, $selector, $keyword, $index=-1) {
    $ret = array();
    foreach ($html->find($selector) as $e) {
        if (strpos($e->innertext, $keyword)!==false)
            $ret[] = $e;
    }

    if ($index<0) return $ret;
    return (isset($ret[$index])) ? $ret[$index] : null;
}
?>
```
