微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php – 从cURL获取Content-Type

这很有助于获得标题
$imageurl = "http://p.twimg.com/AW2-vIUCAAE_1FN.png";

  $ch = curl_init();
  curl_setopt ($ch,CURLOPT_RETURNTRANSFER,1);
  curl_setopt ($ch,CURLOPT_URL,$image_url);
  curl_setopt ($ch,CURLOPT_CONNECTTIMEOUT,20);
  curl_setopt ($ch,CURLOPT_USERAGENT,$_SERVER['HTTP_USER_AGENT']);
  curl_setopt ($ch,CURLOPT_FOLLOWLOCATION,true);
  curl_setopt($ch,CURLOPT_HEADER,true); 
  curl_setopt($ch,CURLOPT_NOBODY,true);

  $content = curl_exec ($ch);

  curl_close ($ch);

  print_r($content);

回国

HTTP/1.1 200 OK
Server: Nginx
X-peep-host: den2twapi014
Last-Modified: Mon,15 Aug 2011 03:41:50 GMT
ETag: "7283847-dbb8-4aa830b1dabf0"
Accept-Ranges: bytes
Content-Length: 56248
Cache-Control: public,max-age=21600
Expires: Wed,28 Mar 2012 15:53:57 GMT
Content-Type: image/png
X-CDN: AKAM
Date: Wed,28 Mar 2012 09:53:57 GMT
Connection: keep-alive

回应Content-Type的最佳方式是什么?

试试这个:-
<?PHP
$image_url = "http://p.twimg.com/AW2-vIUCAAE_1FN.png";

  $ch = curl_init();
  curl_setopt ($ch,true);

  $content = curl_exec ($ch);
  $contentType = curl_getinfo($ch,CURLINFO_CONTENT_TYPE);
    echo $contentType;
    echo "<br/>";
  curl_close ($ch);
    echo "<pre>";
  print_r($content);
  ?>

原文地址:https://www.jb51.cc/php/138361.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐