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_print();
会很酷。HTML 打印基本上是:function html_print($html){
global $doc_html;
$doc_html .= $html;
}
然后,在页面末尾,可以执行
echo html_tidy($doc_html);
这意味着所有由PHP生成的HTML都将被格式化得很好。其他人觉得这是一个好主意吗?默认函数参数会产生错误,因为tidy期望布尔值,但您给的是字符串。第一行应该像这样
function html_tidy( $input_html, $indent = TRUE,
$no_body_tags = TRUE, $fix = TRUE ) {
除此之外,非常好的建议。:-)
$function html_tidy( $input_file, $indent = true, $no_body_tags = false, $fix = true ) {
$tidy = new tidy;
//配置来自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);
}`
要整理HTML,您还可以使用我开发的这个在线工具。
例如
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
您还可以整理其他编程语言http://qwerq.com/doc/Programming