1

应该适用于任何网址的简单代码(我认为):

我不知道为什么我会收到以下警告。任何想法 ?

PHP 警告:DOMDocument::saveHTML(): output conversion failed due to conv error, bytes 0xE9 0x74 0xC3 0xA9 in ********.php on line 9

$content = file_get_contents('http://www.ludibay.net/');
$encoding = mb_detect_encoding($content);
$doc = new DomDocument();

$res = @$doc->loadHTML('<?xml encoding="'.$encoding.'">'.$content);
//some treatment on nodes here
echo $doc->saveHTML();
4

1 回答 1

2

您是否尝试过强制UTF-8 编码,将 iso-8859-1 转换为 UTF-8?我刚才有一个类似的问题,它对我有用。也许尝试:

$content = file_get_contents('http://www.ludibay.net/');
$content = utf8_encode($content); // convert $content to utf_8
$encoding = mb_detect_encoding($content);
$doc = new DomDocument();

$res = @$doc->loadHTML('<?xml encoding="'.$encoding.'">'.$content);
//some treatment on nodes here
echo $doc->saveHTML();
于 2013-08-21T20:15:30.200 回答