PSD to HTML conversion PSD to HTML conversion PSD2HTML.com with over 300 professionals takes the designs to HTML and beyond

Code Snippet

Home » Code Snippets » PHP » HTML Tidy

HTML Tidy

function html_tidy( $input_html, $indent = "true", $no_body_tags = "true", $fix = "true" ) {
   ob_start(  );
   $tidy = new tidy;
   $config = array( 'indent' => $indent, 'output-xhtml' => true, 'wrap' => 200, 'clean' => $fix, 'show-body-only' => $no_body_tags );
   $tidy->parseString( $input_html, $config, 'utf8' );
   $tidy->cleanRepair(  );
   $input = $tidy;
   return $input;
}

Subscribe to The Thread

  1. Zeke N says:

    So, I’m thinking it would be cool to write the function html_print(); HTML print would basically be: function html_print($html){
    global $doc_html;
    $doc_html .= $html;
    }

    Then, at the end of the page, one could do echo html_tidy($doc_html); This would mean all the php generated html would be formatted nicely. Does that sound like a good idea to anyone else?

Speak, my friend

At this moment, you have an awesome opportunity* to be the person your mother always wanted you to be: kind, helpful, and smart. Do that, and we'll give you a big ol' gold star for the day (literally).

Posting tips:
  • You can use basic HTML
  • When posting code, please turn all
    < characters into &lt;
  • If the code is multi-line, use
    <pre><code></code></pre>
Thank you,
~ The Management ~