How can DOM manipulation be achieved in PHP when including HTML files?

When including HTML files in PHP, DOM manipulation can be achieved by loading the HTML content into a DOMDocument object, making the necessary changes, and then outputting the modified HTML.

<?php
// Load the HTML content from the included file
$html = file_get_contents('included_file.html');

// Create a DOMDocument object
$dom = new DOMDocument();
$dom->loadHTML($html);

// Manipulate the DOM as needed
$element = $dom->getElementById('example');
$element->nodeValue = 'New Value';

// Output the modified HTML
echo $dom->saveHTML();
?>