So one thing I've noticed is that DOMDocument->saveHTMLFile() does not create W3C valid HTML. <br> and <img> nodes aren't closed, leading to errors if you want to validate it.
To fix this, I've created a simple function.
<?php
function valid_saveHTMLFile($in,$outputFile) {
$in = preg_replace('/<br(.*?)\/?>/','<br$1/>',$in);
$in = preg_replace('/<img(.*?)\/?>/','<img$1/>',$in);
return file_put_contents($outputFile,$in);
}
?>
to call it
<?php
valid_saveHTMLFile($dom->saveHTML(),'pathtofile');
?>
with $dom being your DOMDocument, and 'pathtofile' being...here's a surprise...the path to your save file.
The function returns the exact same thing file_put_contents returns (ie: The function returns the amount of bytes that were written to the file, or FALSE on failure.)