If you're just looking for a quick and dirty way to output HTML code you created in a formatted way use this technique...<?php$html = 'a chunk of html you created';$config = array( 'indent' => true, 'output-xml' => true, 'input-xml' => true, 'wrap' => '1000');// Tidy$tidy = new tidy();$tidy->parseString($html, $config, 'utf8');$tidy->cleanRepair();echo tidy_get_output($tidy);?>... This seemed to get the result I wanted every time.