Skip to content

Instantly share code, notes, and snippets.

@twoixter
Created January 31, 2012 17:37
Show Gist options
  • Save twoixter/1711769 to your computer and use it in GitHub Desktop.
Save twoixter/1711769 to your computer and use it in GitHub Desktop.
PHP Code to Tidy up PHP output
<?
ob_start();
$__tidy = true;
?>
<body>
<p>this is
a test,
is a
test
<p>Paragraphs automatically
closed
by tidy
<article class="a">
Weird
indented <header data-my-data="b">
html gets fixed
</header>
</article>
</body>
<?
$txtOutput = ob_get_contents();
ob_end_clean();
echo $__tidy ?
// Hack to output an HTML5 DOCTYPE.
// You can use the HTML5-Aware tidy from the W3C repository:
// https://github.com/w3c/tidy-html5.git
"<!DOCTYPE html>\r\n".
tidy_repair_string( $txtOutput,
// Full listing of Tidy Options at:
// http://tidy.sourceforge.net/docs/quickref.html
array(
"indent" => true,
"indent-spaces" => 4,
"logical-emphasis" => true, // Change i => em, b => strong
"hide-comments" => true,
"merge-divs" => false,
"merge-spans" => false,
"quote-ampersand" => true,
"doctype" => "omit",
"output-html" => true,
// Warning! Added new HTML5 elements as a hack.
// See the W3C repo above to include a proper Tidy-HTML5
"new-blocklevel-tags" => "article,header,footer,section,nav",
"new-inline-tags" => "video,audio,canvas,ruby,rt,rp",
"tidy-mark" => false,
"wrap" => 80),
"utf8")
: $txtOutput;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment