tidy, DOMDocument и utf-8

varan

Б̈́̈̽ͮͣ̈Л̩̲̮̻̤̹͓ДͦЖ̯̙̭̥̑͆А͇̠̱͓͇̾ͨД͙͈̰̳͈͛ͅ
tidy, DOMDocument и utf-8

Пытаюсь html в кодировке utf-8 записать в DOMDocument и потом получить обратно. Однако получается абракадабра


PHP:
mytest(file_get_contents('http://www.phpclub.ru/'), 'windows-1251');

    
function mytest($html, $encoding)
{
    
    $html = iconv($encoding, "utf-8", $html);   
    $tidy = new tidy();
    $config = array(
                      'indent'         => true,
                      'output-xhtml'   => true,
                      'wrap'           => 200
                    );
    $tidy->parseString($html, $config, 'utf8');
    $tidy->cleanRepair();
    
    $doc = new DOMDocument();
    
    $html = (string)$tidy;
    
     print($html);
    // здесь всё выводиться корректно, в utf8
    
    $doc->loadHTML($html);
    print $doc->saveHTML(); 
    // здесь всё выводится абракадаброй - это и не виндоус и не utf8
}
 
Сверху