PHP Tidy

windows下,在php.ini里,去除“;extension=php_tidy.dll”前面的“;”。就可以使用tidy扩展了。
extension=php_tidy.dll

[Tidy] tidy.clean_output = Off //是否开启自动 tidy功能。


<?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;
  ?>

你可能感兴趣的:(PHP,tidy)