我使用 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 />';
}
$html 包含俄语文本。在它之后echo $cols->item(2)->nodeValue; 显示错误文本,而不是俄语。我尝试 iconv 但不起作用。有任何想法吗?