dowdw44426 2012-07-11 12:22
浏览 47
已采纳

php下载xml页面并转换为utf-8

when I right-click on the xml page in the browser and save AS , and open it with Notepad++ it appears OK with the non english characters. However if i write a script to save the page to my server, I have issues with character encoding. This is really a headache. Any help? thanks.

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);
  • 写回答

1条回答 默认 最新

  • duanpin2009 2012-07-11 12:59
    关注

    Your code suggests that the result is encoded in UTF-8. First, are you sure it is true? And why do you need to convert it twice (first to 'HTML-ENTITIES', than back to UTF-8)? If you just want to have html entities, use the htmlentities() function.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面