How can PHP preserve the original HTML formatting when working with XML and HTML content?

When working with XML and HTML content in PHP, the original HTML formatting can be preserved by using the `DOMDocument` class to parse and manipulate the content. This class allows you to load HTML content, make changes to it, and then output the modified content while preserving the original formatting.

// Load the HTML content into a DOMDocument
$dom = new DOMDocument();
$dom->loadHTML($html_content);

// Make changes to the content here

// Output the modified content while preserving the original formatting
echo $dom->saveHTML();