开发者

PHP curl_getinfo($ch, CURLINFO_CONTENT_TYPE) returns no charset

开发者 https://www.devze.com 2023-02-06 06:13 出处:网络
I have the following PHP code: 开发者_Go百科<?php # URL #1 $ch = curl_init(\'http://www.google.com/\');

I have the following PHP code:

开发者_Go百科
<?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;
  
?>

Returns following result:

text/html charset=UTF-8

text/html

So I am missing the charset for the second URL. I checked the html code and the charset is there.

Why is the curl_getinfo not getting the charset in the second case?


This information is not sent in the HTML code, but in the HTTP headers. If the curl_getinfo call does not return it, the server did not send it in its HTTP headers.

0

精彩评论

暂无评论...
验证码 换一张
取 消