如何使用 CURL 代替 file_get_contents?
2022-08-30 12:22:04
我使用函数在我的特定页面上获取和显示外部链接。file_get_contents
在我的本地文件中,一切都很好,但我的服务器不支持该功能,所以我尝试使用以下代码使用cURL:file_get_contents
function file_get_contents_curl($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
echo file_get_contents_curl('http://google.com');
但它返回一个空白页。怎么了?