博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
使用PHP cURL下载URL的内容
阅读量:2512 次
发布时间:2019-05-11

本文共 891 字,大约阅读时间需要 2 分钟。

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.

另外,您可以远程使用函数,但是许多主机不允许这样做。

翻译自:

转载地址:http://mkpwd.baihongyu.com/

你可能感兴趣的文章
JDK工具(一)–Java编译器javac
查看>>
深入.NET框架与面向对象的回顾
查看>>
改变label中的某字体颜色
查看>>
七牛云存储之应用视频上传系统开心得
查看>>
struts2日期类型转换
查看>>
Spark2-数据探索
查看>>
Http和Socket连接区别
查看>>
Angular2,Springboot,Zuul,Shiro跨域CORS请求踩坑实录
查看>>
C语言中操作符的优先级大全
查看>>
pgpool-II - 介绍
查看>>
Alpha冲刺(10/10)——2019.5.2
查看>>
图书管理系统用例
查看>>
Microsoft patterns & practices 学习笔记(0)
查看>>
在腾讯云上创建您的SQL Cluster(4)
查看>>
部署在腾讯云的公益网站遭受了一次CC攻击
查看>>
linux ping命令
查看>>
Activiti源码浅析:Activiti的活动授权机制
查看>>
数位dp整理
查看>>
UNIX基础知识
查看>>
bzoj 1179: [Apio2009]Atm
查看>>