This class overcomes a few common annoyances with the DOMDocument class, such as saving partial HTML without automatically adding extra tags and properly recognizing various encodings, specifically UTF-8.

To Install

In composer.json, add the repository:

"repositories": [
            "type": "vcs",
            "url": ""
    "require": {
        "archon810/smartdomdocument": "dev-master"

Then run

composer update

This will install smartdomdocument, as well as PHPUnit, if you set composer to download dev dependencies.

(Use --no-dev to disable dev deps)

To Use

$dom = new \archon810\SmartDOMDocument();
 * Make some changes to $dom...
$content = $dom->saveHTMLExact();

To Test



This will pickup the correct config from phpunit.xml and run the tests in ./test