User Contributed Notes 3 notes

saveHTMLFile() always saves the file in UTF-8. Even if the DOMDocument->encoding explicitly prescribe different from UTF-8 encoding. All "non-Latin" characters will be converted to HTML-entities. Tested in PHP 5.2.9-2 and PHP 5.2.17. Example:

If you're dynamically generating a series of pages using DOMDocument objects, make sure you are also dynamically generating the file or directory names using something that can't easily be confused for an existing file/folder, or check if the desired path already exists before saving so that you don't accidentally delete previous files.

I foolishly assumed that this function was equivalent to<?phpfile_put_contents($filename, $document->saveHTML());?>but there are differences in the generated HTML:<?php$doc = new DOMDocument();$doc->loadHTML('<html><head><title>Test</title></head><body></body></html>');$doc->encoding = 'iso-8859-1';