0

XpathでWebスクレイピングを学ぼうとしています。以下のコードは機能しますが、出力に間違った文字が含まれているため、これを正しく行うことができません。

例:

  • 出力: エメジェリエ
  • あるべき姿: 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";
}
?>

これを修正するにはどうすればよいですか?

4

1 に答える 1

1

ISO8859-15 を使用している場合はencode() & decode() php関数を、そうでない場合はiconv()を試してください。

例 :

<?php
iconv_set_encoding("internal_encoding", "UTF-8");
iconv_set_encoding("output_encoding", "ISO-8859-1");
?>
于 2012-11-18T19:52:00.393 に答える