dttl3933 2013-08-05 08:47
浏览 85
已采纳

cURL PHP奇怪的人物

I need your help with cURL in PHP.

I'm trying to get a page and convert it in JSON but I have strange character in my cURL response :  thus I can't convert it. This characters are displayed just before the !doctype of the page that I am looking for.

I set header('Content-type: text/html; charset=utf-8'); in PHP and I used

'Accept: text/xml,application/xml,application/xhtml+xml',
        'text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5',
        'Accept-Language: fr-fr,fr;q=0.7,en-us;q=0.5,en;q=0.3',
        'Accept-Charset: utf-8;q=0.7,*;q=0.7',
        'Keep-Alive: 300');

for cURL.

cURL Code :

$ch = curl_init($searchUrl);

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);        
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);           
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);            
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_setopt($ch, CURLOPT_HEADER, $header);          
curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');             
curl_setopt($ch, CURLOPT_USERAGENT, $agents[rand(0, count($agents) - 1)]);

$response = curl_exec($ch);

curl_close($ch);

Anyone has an idea ?

  • 写回答

1条回答 默认 最新

  • duanpanhuo0618 2013-08-05 09:08
    关注

    Those 3 initial characters are called a BOM mark. It's used to determine the encoding of a file. You can attempt to strip it by substringing the HTML response:

    $response = substr($response, 3);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器