PHP curl_getinfo($ch, CURLINFO_CONTENT_TYPE) returns no charset
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.
精彩评论