PHP curl

WBOY
Lepaskan: 2016-07-29 08:56:55
asal
974 orang telah melayarinya

什么是curl

curl是利用URL语法在命令行方式下工作的开源文件传输工具。

PHP 的用处

使用PHP的cURL库可以简单和有效地去抓网页。你只需要运行一个脚本,然后分析一下你所抓取的网页,然后就可以以程序的方式得到你想要的数据了。无论是你想从从一个链接上取部分数据,或是取一个XML文件并把其导入数据库,那怕就是简单的获取网页内容,cURL 是一个功能强大的PHP库。

demo1

<code><span><span><?php </span><span>//1.初始化,创建一个新cURL资源 </span><span>$ch</span> = curl_init();
    <span>//2.设置URL和相应的选项</span>
    curl_setopt(<span>$ch</span>, CURLOPT_URL, <span>"http://www.lampbrother.net/"</span>) 
    curl_setopt(<span>$ch</span>, CURLOPT_HEADER, <span>0</span>); 
    <span>//3.抓取URL并把它传递给浏览器 </span><span>$data</span> = curl_exec(<span>$ch</span>); 
    <span>//4.显示获得的数据</span>
    var_dump(<span>$data</span>);
    <span>//5.关闭cURL资源,并且释放系统资源 </span>
    curl_close(<span>$ch</span>);
<span>?></span></span></span></code>
Salin selepas log masuk

demo2 post数据

<code>﹤?php
<span>$phoneNumber</span> = <span>'13812345678'</span>;
<span>$message</span> = <span>'This message was generated by curl and php'</span>;
<span>$curlPost</span> = <span>'pNUMBER='</span> . urlencode(<span>$phoneNumber</span>) . <span>'&MESSAGE='</span> . urlencode(<span>$message</span>) . <span>'&SUBMIT=Send'</span>;
<span>$ch</span> = curl_init();
curl_setopt(<span>$ch</span>, CURLOPT_URL, <span>'http://www.lxvoip.com/sendSMS.php'</span>);
curl_setopt(<span>$ch</span>, CURLOPT_HEADER, <span>1</span>);
curl_setopt(<span>$ch</span>, CURLOPT_RETURNTRANSFER, <span>1</span>);
curl_setopt(<span>$ch</span>, CURLOPT_POST, <span>1</span>);
curl_setopt(<span>$ch</span>, CURLOPT_POSTFIELDS, <span>$curlPost</span>);
<span>$data</span> = curl_<span>exec</span>();
curl_close(<span>$ch</span>);
?﹥</code>
Salin selepas log masuk

demo3 使用代理服务器

<code>﹤?php 
<span>$ch</span> = curl_init();
curl_setopt(<span>$ch</span>, CURLOPT_URL, <span>'http://www.cmx8.cn'</span>);
curl_setopt(<span>$ch</span>, CURLOPT_HEADER, <span>1</span>);
curl_setopt(<span>$ch</span>, CURLOPT_RETURNTRANSFER, <span>1</span>);
curl_setopt(<span>$ch</span>, CURLOPT_HTTPPROXYTUNNEL, <span>1</span>);
curl_setopt(<span>$ch</span>, CURLOPT_PROXY, <span>'proxy.lxvoip.com:1080'</span>);
curl_setopt(<span>$ch</span>, CURLOPT_PROXYUSERPWD, <span>'user:password'</span>);
<span>$data</span> = curl_<span>exec</span>();
curl_close(<span>$ch</span>);
?﹥</code>
Salin selepas log masuk
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

以上就介绍了PHP curl,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan