Skip to content

Instantly share code, notes, and snippets.

@RundesBalli
Created September 13, 2020 13:53
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
PHP-Snippet: Tidy HTML Output

Small snippet for the PHP-Tidy function

turns this:

<html><body><p>your HTML code here</p></body></html>

into this:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title></title>
  </head>
  <body>
    <p>
      your HTML code here
    </p>
  </body>
</html>
<?php
$output = "<html><body><p>your HTML code here</p></body></html>";
/**
* @see https://api.html-tidy.org/tidy/quickref_5.6.0.html
*/
$tidyOptions = array(
'indent' => TRUE,
'output-xhtml' => TRUE,
'wrap' => 200,
'newline' => 'LF', /* LF = \n */
'output-encoding' => 'utf8',
'drop-empty-elements' => FALSE /* e.g. for placeholders */
);
$tidy = tidy_parse_string($output, $tidyOptions, 'UTF8');
tidy_clean_repair($tidy);
echo $tidy;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment