Skip to content

Instantly share code, notes, and snippets.

Created September 13, 2020 13:53
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="">
      your HTML code here
$output = "<html><body><p>your HTML code here</p></body></html>";
* @see
$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');
echo $tidy;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment