$dom = new DOMDocument();
$dom->loadHTMLFile($file);
// Действия
$dom->saveHTMLFile($file);
$dom = new DOMDocument('1.0', 'UTF-8');
$dom->formatOutput = true;
$content = file_get_contents($file);
$content = mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8');
$dom->loadHTML($content);
$dom->encoding = 'UTF-8';
$html = $dom->saveHTML();
file_put_contents($file, $html);