windows下,在php.ini裏,去除「;extension=php_tidy.dll」前面的「;」。就可使用tidy擴展了。 extension=php_tidy.dll [Tidy] tidy.clean_output = Off //是否開啓自動 tidy功能。
<!-- lang: php -->
<?php
$html = <<<EOD
<html>
<head>
<title>test</title>
</head>
<body>
<p>error<br>another line</i>
EOD;
$config = array('indent' => TRUE, //是否縮進
'output-xhtml' => TRUE,//是不是輸出xhtml
'show-body-only'=>TRUE,//是否只得到到body
'wrap' => 200);
$tidy = tidy_parse_string($html, $config, 'UTF8');
$tidy->cleanRepair();
echo $tidy;
$tidy = new Tidy;
$tidy->parseString($html, $config, 'utf8');
$tidy->cleanRepair();
echo $tidy;
$clean = $tidy->repairString($html, $config, 'utf8');
echo $clean;
?>