Skip to content

Instantly share code, notes, and snippets.

@Eccenux
Created August 5, 2014 11:07
Show Gist options
  • Save Eccenux/edfb68f0e4745f16af19 to your computer and use it in GitHub Desktop.
Save Eccenux/edfb68f0e4745f16af19 to your computer and use it in GitHub Desktop.
PHP DOM parser - problem with HTML whitespace
<!DOCTYPE html>
<!--
Copyright: ©2014 Nux
License: CC0
-->
<html>
<head>
<title>Test</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta charset="UTF-8">
</head>
<body>
<div data-lang="en">
<p>Some national characters: żść.</p>
<p>App version 0.1.1.</p>
<ul>
<li>Create model with JSON.</li>
<li>Append views to HTML</li>
<li>Add interactions in controllers.</li>
<li>Test in any browser.</li>
<li>Package.</li>
<li>Run anywhere.</li>
</ul>
</div>
</body>
</html>
<!DOCTYPE html>
<!--
Copyright: &Acirc;&copy;2014 Nux
License: CC0
--><html><head><title>Test</title><meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"><meta charset="UTF-8"></head><body>
<div data-lang="en">
<p>Some national characters: &Aring;&frac14;&Aring;&#155;&Auml;&#135;.</p>
<p>App version 0.1.1.</p>
<ul><li>Create model with JSON.</li>
<li>Append views to HTML</li>
<li>Add interactions in controllers.</li>
<li>Test in any browser.</li>
<li>Package.</li>
<li>Run anywhere.</li>
</ul></div>
</body></html>
<?php
$inputFile = 'index.mini.html';
$html = file_get_contents($inputFile);
$document = new DOMDocument();
$document->loadHTML($html);
$parsed_html = $document->saveHTML();
echo $parsed_html;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment