What are some recommended PHP HTML parsers for parsing entire HTML files while retaining formatting?

When parsing entire HTML files in PHP, it's essential to retain the formatting to ensure the structure and styling are preserved. One way to achieve this is by using PHP HTML parsers that can handle the parsing process while keeping the original formatting intact. Some recommended PHP HTML parsers for this purpose include Simple HTML DOM Parser, PHP Simple HTML DOM Parser, and Goutte.

// Example using Simple HTML DOM Parser
include('simple_html_dom.php');

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

// Process the HTML file while retaining formatting
foreach($html->find('p') as $element){
    echo $element->outertext;
}