【发布时间】: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