我试图通过使用cURL来获取Facebook主页的源代码,但由于我的服务器主机的位置,它全部都是中文。出于这个原因,我添加了Accept-Language
CURLOPT_HTTPHEADER
来将语言更改为英语,但失败了。根据我上面引用的答案,下面是我试过的cURL的PHP代码:
<?php
$url = "http://www.facebook.com/";
if(isset($_SERVER['HTTP_USER_AGENT']))
$user_agent = $_SERVER['HTTP_USER_AGENT'];
else
$user_agent = "";
$options = array(
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => false, // don't return headers
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_HTTPHEADER => array("Accept-Language: en-US;q=0.6,en;q=0.4"),
CURLOPT_USERAGENT => $user_agent);
$ch = curl_init($url);
curl_setopt_array($ch, $options);
$content = curl_exec($ch);
$err = curl_errno($ch);
$errmsg = curl_error($ch);
$header = curl_getinfo($ch);
curl_close($ch);
echo $content;
?>
但它仍显示中文:
我该如何解决这个问题?