应该适用于任何网址的简单代码(来自我的意见):
我无法理解为什么会收到以下警告。有什么想法吗?
PHP警告:DOMDocument :: saveHTML():由于转换错误导致输出转换失败,第9行的********。php中的字节0xE9 0x74 0xC3 0xA9
$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();
答案 0 :(得分:2)
你有没有试过强制UTF-8 encoding,它从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();