1
当我右键单击浏览器中的xml页面并保存AS时,使用Notepad ++打开它时,它显示OK并显示非英文字符。 但是,如果我编写一个脚本来将页面保存到我的服务器,我遇到了字符编码问题。这真是一件令人头疼的事情。任何帮助?谢谢。php下载xml页面并将其转换为utf-8
function download_page($path)
{
//$path = htmlentities($path);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$path);
curl_setopt($ch, CURLOPT_FAILONERROR,1);
//curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 280);
$retValue = curl_exec($ch);
if (!$retValue){ //echo "erro curl";
}
@curl_close($ch);
return $retValue;
}
$file= download_page($url);
$file = mb_convert_encoding($file, 'HTML-ENTITIES', "UTF-8");
$file = utf8_encode ($file);
我需要非英文字符出现(ě,ú,..) – karto 2012-07-11 13:16:18
如果您有适当的utf-8文件,它们应该会出现。我认为你不需要mb_convert_encoding行。但你如何写出文件?你使用fwrite吗?如果是,请检查[this](http://hu.php.net/manual/en/function.fwrite.php#73764)。这是一个有点旧的帖子,但它可能有帮助。 – ttamas 2012-07-11 14:08:16