Downloading content at a specific URL is common practice on the internet, especially due to increased usage of web services and APIs offered by Amazon, Alexa, Digg, etc. PHP's cURL library, which often comes with default shared hosting configurations, allows web developers to complete this task.
在特定的URL上下载内容是Internet上的常见做法,尤其是由于Amazon,Alexa,Digg等提供的Web服务和API的使用增加。PHP的cURL库通常带有默认的共享托管配置,允许Web开发人员执行以下操作:完成此任务。
代码 (The Code)
/* gets the data from a URL */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;}
用法 (The Usage)
$returned_content = get_data('https://davidwalsh.name');
Alternatively, you can use the function remotely, but many hosts don't allow this.
另外,您可以远程使用函数,但是许多主机不允许这样做。
翻译自: