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;
}
HTML Tidy
Chris Coyier
on
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?The default function arguments would produce an error since tidy expects a boolean value, but you’re giving a string. The first line should be like so:
function html_tidy( $input_html, $indent = TRUE,
$no_body_tags = TRUE, $fix = TRUE ) {
Other than that, very good suggestion. :-)
$function html_tidy( $input_file, $indent = true, $no_body_tags = false, $fix = true ) {
$tidy = new tidy;
//config is from http://tidy.sourceforge.net/docs/quickref.html
$config = array( ‘indent’ => $indent,
‘output-html’ => true,
‘wrap-attributes’ => false,
‘wrap’ => 120,
‘show-body-only’ => $no_body_tags
);
$tidy->parseFile( $input_file, $config );
$tidy->cleanRepair( );
return tidy_get_output($tidy);
}`
To tidy the HTML, you can also use this online tool that I develop.
e.g.
http://qwerq.com/?q=tidy+html&qr1=%3C%21DOCTYPE%20html%3E%3Chtml%3E%3Chead%3E%3C%2Fhead%3E%3Cbody%3E%3Cp%3EHello%20World%21%3C%2Fp%3E%3C%2Fbody%3E%3C%2Fhtml%3E
you can also tidy other programming language http://qwerq.com/doc/Programming