将file_get_content()替换为cURL? [英] Replace file_get_content() with cURL?

查看:134
本文介绍了将file_get_content()替换为cURL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不想使用这个函数,因为它在某些服务器不可用的安全原因,我如何替换file_get_content()与cURL?

I don't want to use this function because to it's unavailability on some servers for security reasons, how can i replace file_get_content() with cURL ?

以下是我的伺服器发生问题:

The line below is causing me a problem on my server :

$response = file_get_contents('http://images.google.com/images?hl=en&q=' . urlencode ($query) . '&imgsz=' . $size . '&imgtype=' . $type . '&start=' . (($page - 1) * 21));

如何将行替换为另一个使用curl的行,因此它将在每个服务器上工作? / p>

How can i replace the line with another one that uses curl so it will work on every server ?

推荐答案

这里是一个可以使用的清理函数

here is a clean function you can use

$response = get_data('http://images.google.com/images?hl=en&q=' . urlencode ($query) . '&imgsz=' . $size . '&imgtype=' . $type . '&start=' . (($page - 1) * 21));

function get_data($url)
{
  $ch = curl_init();
  $timeout = 5;
  curl_setopt($ch,CURLOPT_URL,$url);
  curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
  $data = curl_exec($ch);
  curl_close($ch);
  return $data;
}

这篇关于将file_get_content()替换为cURL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆