【问题标题】:PHP curl_getinfo($ch, CURLINFO_CONTENT_TYPE) returns no charsetPHP curl_getinfo($ch, CURLINFO_CONTENT_TYPE) 不返回字符集
【发布时间】:2011-01-20 13:09:34
【问题描述】:

我有以下 PHP 代码:

<?php
  # URL #1
  $ch = curl_init('http://www.google.com/');
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_exec($ch);
  # get the content type
  $content_type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
  echo $content_type;
  echo "<br>";
  
  # URL #2
  $ch = curl_init('http://www.lemonde.fr/');
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_exec($ch);
  # get the content type
  $content_type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
  echo $content_type;
  
?>

返回以下结果:

文本/html charset=UTF-8

文本/html

所以我缺少第二个 URL 的字符集。我检查了 html 代码,字符集在那里。

为什么 curl_getinfo 在第二种情况下没有得到字符集?

【问题讨论】:

    标签: php curl character-encoding


    【解决方案1】:

    此信息不是在 HTML 代码中发送的,而是在 HTTP 标头中发送的。如果 curl_getinfo 调用没有返回它,则服务器没有在其 HTTP 标头中发送它。

    【讨论】:

    • 啊!那讲得通。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-11
    • 2015-07-29
    • 2017-09-24
    • 2012-06-18
    • 2014-02-09
    • 1970-01-01
    相关资源
    最近更新 更多