2012-11-18 35 views
0

我在尝试使用Xpath学习网页抓取。下面的代码工作,但输出包含不正确的字符,我无法设法得到这个权利。输出中的字符不正确

例子:

  • 输出:EmÃ¥mejeriet
  • 应该如何:Emåmejeriet

PHP代码:

<?php 
// Tried with these parameters but they doesn't make any difference 
$html = new DOMDocument('1.0', 'UTF-8'); 
$html->loadHtmlFile('http://thesite.com/thedoc.html); 
$xpath = new DOMXPath($html); 
$nodelist = $xpath->query("//table"); 
foreach ($nodelist as $n) { 
    echo $n->nodeValue."\n"; 
} 
?> 

我能做些什么来解决这个问题?

回答

1

如果使用ISO8859-15或iconv()如果不是你应该尝试encode() & decode()php功能。

实施例:

<?php 
iconv_set_encoding("internal_encoding", "UTF-8"); 
iconv_set_encoding("output_encoding", "ISO-8859-1"); 
?>