俄语的php问题

kus*_*agi 3 php encoding curl iconv domdocument

我使用curl以俄语填写utf-8页面.如果我回复文本它显示良好.然后我使用这样的代码

$dom = new domDocument; 

        /*** load the html into the object ***/ 
        @$dom->loadHTML($html); 

        /*** discard white space ***/ 
        $dom->preserveWhiteSpace = false; 

        /*** the table by its tag name ***/ 
        $tables = $dom->getElementsByTagName('table'); 

        /*** get all rows from the table ***/ 
        $rows = $tables->item(0)->getElementsByTagName('tr'); 

        /*** loop over the table rows ***/ 
        for ($i = 0; $i <= 5; $i++)
        { 
            /*** get each column by tag name ***/ 
            $cols = $rows->item($i)->getElementsByTagName('td'); 

            echo $cols->item(2)->nodeValue; 

            echo '<hr />'; 
        } 
Run Code Online (Sandbox Code Playgroud)

$ html包含俄语文本.在它行echo $ cols-> item(2) - > nodeValue之后; 显示错误文本,而不是俄语.我尝试iconv但不工作.有任何想法吗?

Asi*_*lla 12

我建议在加载UTF-8页面之前使用mb_convert_encoding.

    $dom = new DomDocument();   
    $html = mb_convert_encoding($html, 'HTML-ENTITIES', "UTF-8");
    @$dom->loadHTML($html);

或者你可以试试这个

    $dom = new DomDocument('1.0', 'UTF-8');
    @$dom->loadHTML($html);
    $dom->preserveWhiteSpace = false;
    ..........
    echo html_entity_decode($cols->item(2)->nodeValue,ENT_QUOTES,"UTF-8");
    ..........