PHP curl_getinfo($ ch,CURLINFO_CONTENT_TYPE)不返回字符集 [英] PHP curl_getinfo($ch, CURLINFO_CONTENT_TYPE) returns no charset
本文介绍了PHP curl_getinfo($ ch,CURLINFO_CONTENT_TYPE)不返回字符集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下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;
?>
返回下列结果:
text / html charset = UTF-8
text/html charset=UTF-8
text / html
text/html
$ b b
所以我缺少第二个URL的字符集。我检查了html代码和字符集是有。
So I am missing the charset for the second URL. I checked the html code and the charset is there.
为什么curl_getinfo在第二种情况下没有获取字符集?
Why is the curl_getinfo not getting the charset in the second case?
推荐答案
此信息不是在HTML代码中发送,而是在HTTP标头中发送。如果curl_getinfo调用没有返回它,则服务器没有在其HTTP头中发送它。
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.
这篇关于PHP curl_getinfo($ ch,CURLINFO_CONTENT_TYPE)不返回字符集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文