CURL中文乱码

Alex_1024 2013-01-23 11:13:22

<?php
$url = "http://www.gewara.com/cinema/ajax/getCinemaPlayItem.xhtml?cid=64915153&mid=&fyrq=2013-01-24";
$ch= curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_exec($ch);
curl_close($ch);
?>


$url的时间请调整为当天或者明天~ 为什么会是乱码?
...全文
869 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
xuzuning 2013-01-24
  • 打赏
  • 举报
回复
你写反了! 是 $contents = mb_convert_encoding($contents, "gb2312", "UTF-8"); 不是 $contents = mb_convert_encoding($contents, "UTF-8", "gb2312");
一起混吧 2013-01-24
  • 打赏
  • 举报
回复
header("content-type:text/html;charset=utf-8"); //指定下字符集
Alex_1024 2013-01-24
  • 打赏
  • 举报
回复
引用 2 楼 aoecal 的回复:
对方是utf8的,你必须强制使用u8编码....
<?php
$url = "http://www.gewara.com/cinema/ajax/getCinemaPlayItem.xhtml?cid=64915153&mid=&fyrq=2013-01-24";
$useragent = "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.56 Safari/537.17";
$ch= curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_HEADER, 1);    
$contents=curl_exec($ch);
curl_close($ch);
$contents = mb_convert_encoding($contents, "UTF-8", "gb2312");
echo $contents;
?>
试过了 还是不行啊 gb2312和gbk都试过了
aoecal 2013-01-24
  • 打赏
  • 举报
回复
对方是utf8的,你必须强制使用u8编码....
aoecal 2013-01-24
  • 打赏
  • 举报
回复
注意下编码~~

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧