- str_replace: documentation ( source)
- trim: documentation ( source)
<?php
echo "LIBXML_DOTTED_VERSION: " . LIBXML_DOTTED_VERSION . "\n\n";
$dom = new DOMDocument( '1.0', 'UTF-8' );
$dom->preserveWhiteSpace = true;
$dom->formatOutput = false;
$dom->substituteEntities = false;
$dom->resolveExternals = true;
$dom->loadHTML( "<!DOCTYPE html><html><head><meta charset=utf-8></head><body><ul><li>one</li><li>two</li></ul></html>" );
echo "# \$dom->saveHTML( \$dom->documentElement ):\n";
$first = trim( $dom->saveHTML( $dom->documentElement ) );
echo $first;
echo "\n";
echo "\n";
echo "# ~\$dom->saveHTML():\n";
$second = trim( str_replace( "<!DOCTYPE html>\n", "", $dom->saveHTML() ) );
echo $second;
echo "\n\n";
echo $first === $second ? "PASS" : "FAIL";