What are the potential pitfalls of using DomDoc to search for HTML comments in PHP?

Potential pitfalls of using DomDoc to search for HTML comments in PHP include the fact that DomDoc may not always accurately parse comments, especially if the HTML structure is complex or malformed. To avoid this issue, a more reliable approach would be to use regular expressions to directly search for HTML comments in the raw HTML string.

$html = file_get_contents('example.html');

// Use regular expressions to search for HTML comments
preg_match_all('/<!--(.*?)-->/s', $html, $matches);

// Output all found HTML comments
foreach ($matches[0] as $comment) {
    echo $comment . "<br>";
}