如何修复saveHTML():由于转换错误,输出转换失败? [英] How to fix saveHTML(): output conversion failed due to conv error?

查看:120
本文介绍了如何修复saveHTML():由于转换错误,输出转换失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

应该适用于任何网址的简单代码(从我的意见):

Simple code that should work on any url (from my opinion) :

我无法确定为什么我会收到以下警告。任何想法?

I cannot figure why do i get the following Warning. Any idea ?


PHP警告:DOMDocument :: saveHTML():由于转换错误,输出转换失败,字节0xE9 0x74 0xC3 0xA9 in * *******。第9行的PHP php

PHP Warning: 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();


推荐答案

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

Have you tried to force UTF-8 encoding, which converts from iso-8859-1 to UTF-8? I had a similar issue just now, and it worked for me. Maybe try:

$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();

这篇关于如何修复saveHTML():由于转换错误,输出转换失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆