Skip to content

Instantly share code, notes, and snippets.

@pschultz
Created December 7, 2012 10:58
Show Gist options
  • Save pschultz/4232482 to your computer and use it in GitHub Desktop.
Save pschultz/4232482 to your computer and use it in GitHub Desktop.
DomDocument::$preserveWhitespace and ::saveHtml()
$doc = new DomDocument;
$doc->preserveWhitespace = true;
$doc->formatOutput = false;
$doc->loadHtml(
'<ul id="ProjectSubmenu">
<li><a href="/projects/markdown/" title="Markdown Project Page">Main</a></li>
<li>
<a href="/projects/markdown/basics" title="Markdown Basics">Basics</a>
</li>
<li><a class="selected" title="Markdown Syntax Documentation">Syntax</a></li>
<li><a href="/projects/markdown/license" title="Pricing and License Information">License</a></li>
<li><a href="/projects/markdown/dingus" title="Online Markdown Web Form">Dingus</a></li>
</ul>'
);
$listNode = $doc->getElementsByTagName('ul')->item(0);
echo $doc->saveHtml($listNode);
<ul id="ProjectSubmenu">
<li><a href="/projects/markdown/" title="Markdown Project Page">Main</a></li>
<li>
<a href="/projects/markdown/basics" title="Markdown Basics">Basics</a>
</li>
<li><a class="selected" title="Markdown Syntax Documentation">Syntax</a></li>
<li><a href="/projects/markdown/license" title="Pricing and License Information">License</a></li>
<li><a href="/projects/markdown/dingus" title="Online Markdown Web Form">Dingus</a></li>
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment