$buffer = "<html>
  <head>
    <title>test</title>
  </head>
  <body>
   <div>
        <p>indent: 代码缩进,可选auto,yes,no,在php中,填auto将会被默认为yes,所以,此项在php中可分别用2,1,0来表示,2表示auto,1表示yes,0表示no不开启。wrap:换行,用0表示不换行。output-xhtml:输出xhtml格式文档。
        </p>
    </div>
 </div>
  </body>
</html>";$outstr = tidy_repair_string($buffer, array("input-encoding"=>"utf8","output-encoding"=>"utf8"), "utf8");echo $outstr;这个是代码, 但是浏览器显示出来得时乱码
是不是tidy本身不支持中文,还是我哪个地方写错了呀。请教大家了。

解决方案 »

  1.   

    $outstr = tidy_repair_string($buffer, array('char-encoding' => 'utf8'); //这样呢?
      

  2.   

    $outstr = tidy_repair_string($buffer, array('char-encoding' => 'utf8')); //抱歉,上面漏掉个括号
      

  3.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">
    <html>
    <head>
    <title>test</title>
    </head>
    <body>
    <div>
    <p>indent:
    &acute;&uacute;&Acirc;&euml;&Euml;&otilde;&frac12;&oslash;&pound;&not;&iquest;&Eacute;&Ntilde;&iexcl;auto,yes,no&pound;&not;&Ocirc;&Uacute;php&Ouml;&ETH;&pound;&not;&Igrave;&icirc;auto&frac12;&laquo;&raquo;&aacute;&plusmn;&raquo;&Auml;&not;&Egrave;&Iuml;&Icirc;&ordf;yes,&Euml;&ugrave;&Ograve;&Ocirc;&pound;&not;&acute;&Euml;&Iuml;&icirc;&Ocirc;&Uacute;php&Ouml;&ETH;&iquest;&Eacute;&middot;&Ouml;&plusmn;&eth;&Oacute;&Atilde;2,1,0&Agrave;&acute;&plusmn;&iacute;&Ecirc;&frac34;&pound;&not;2&plusmn;&iacute;&Ecirc;&frac34;auto,1&plusmn;&iacute;&Ecirc;&frac34;yes,0&plusmn;&iacute;&Ecirc;&frac34;no&sup2;&raquo;&iquest;&ordf;&AElig;&ocirc;&iexcl;&pound;wrap:&raquo;&raquo;&ETH;&ETH;&pound;&not;&Oacute;&Atilde;0&plusmn;&iacute;&Ecirc;&frac34;&sup2;&raquo;&raquo;&raquo;&ETH;&ETH;&iexcl;&pound;output-xhtml&pound;&ordm;&Ecirc;&auml;&sup3;&ouml;xhtml&cedil;&ntilde;&Ecirc;&frac12;&Icirc;&Auml;&micro;&micro;&iexcl;&pound;</p>
    </div>
    </body>
    </html> 
     这个是运行后的结果
    还是不行
      

  4.   

    补充,既然是指定utf8编码,那你的PHP文件是不是用utf8编码保存的?PHP文件head标签中有没有设置文档编码:
    <meta http-equiv="Content-Type" content="text/html; charset=utf8" />
      

  5.   

    我的php版本是5.2.17
    开始的时候,没有装tidy, 这个是我刚刚安装上去的如果没有中文, 显示结果正确,但是有中文后就不行了
    不知道为什么
      

  6.   


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
            "http://www.w3.org/TR/html4/loose.dtd">
    <html><head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    </head>
    <?php
    header("Content-Type: text/html; charset=utf8");
    $buffer = "<html>
      <head>
        <title>test</title>
      </head>
      <body>
       <div>
            <p>indent: 代码缩进,可选auto,yes,no,在php中,填auto将会被默认为yes</p>
        </div>
     </div>
      </body>
    </html>";
    $outstr = tidy_repair_string($buffer, array('char-encoding'=>'utf8')); 
    echo $outstr;
    ?></html>
    这个是全部代码, 文件格式是UTF-8 无bom格式的。
    结果还是乱码。  浏览器解释成utf8了。
    不清楚为什么是乱码
      

  7.   

    $outstr = tidy_repair_string($buffer, array('output-xhtml' => true), 'utf8'); //这样呢
      

  8.   

    哦。。我脑子短路了。
    把下面的代码保存为php文件,看看执行结果。(DTD、html代码全都去掉)<?php
    $buffer = "<html>
      <head>
        <title>test</title>
      </head>
      <body>
          <div>
            <p>indent: 代码缩进,可选auto,yes,no,在php中,填auto将会被默认为yes</p>
        </div>
     </div>
      </body>
    </html>";
    $outstr = tidy_repair_string($buffer, array('output-xhtml' => true), 'utf8');
    echo $outstr;
    ?>
      

  9.   

    恩, 你这个也是对的。本来我使用的是
    $outstr = tidy_repair_string($buffer, array('input-encoding'=>'utf8','output-encoding"=>"utf8', 'char-encoding' => 'utf8'), "utf8"); 不知道为什么显示的不对, 现在倒是可以的了,
    可能是我没有注意把文件格式转换成UTF-8的
    现在是可以的了。
    第一次用这个东西,网上搜了一下,确实有价值的资料不是很多。
    谢谢你了