代碼如下:
$ch = curl_init();
$c_url = 'http://www.bkjia.com;
$c_url_data = "product_&type=".$type."";
curl_setopt($ch, curlopt_url,$c_url);
curl_setopt($ch, curlopt_post, 1);
curl_setopt($ch, curlopt_returntransfer, true);
curl_setopt($ch, curlopt_postfields, $c_url_data);
echo $result = curl_exec($ch);
curl_close ($ch);
unset($ch);
在php教程中使用curl
posted 09月 14th, 2008 歸屬於php
原文(英文)地址: http://www.phpit.net/article/using-curl-php 著作權聲明:署名-非商業性使用-禁止演繹 2.0
摘要:
在這篇文章中主要講解php_curl庫的知識,並教你如何更好的使用php_curl。
簡介
你可能在你的編寫php指令碼代碼中會遇到這樣的問題:怎麼樣才能從其他網站擷取內容呢?這裡有幾個解決方式;最簡單的就是在php中使用fopen()函數,但是fopen函數沒有足夠的參數來使用,比如當你想構建一個“網路爬蟲”,想定義爬蟲的用戶端描述(ie,firefox),通過不同的請求方式來擷取內容,比如post,get;等等這些需求是不可能用fopen()函數實現的。
為瞭解決我們上面提出的問題,我們可以使用php的擴充庫-curl,這個擴充庫通常是預設在安裝包中的,你可以它來擷取其他網站的內容,也可以來幹別的。
備忘:這兩段代碼需要php_curl擴充庫的支援,查看phpinfo(),如果curl support enabled則表示支援curl庫。
1、windows下的php開啟curl庫支援:
開啟php.ini,將extension=php_curl.dll前的;號去掉。
2、linux下的php開啟curl庫支援:
編譯php時在./configure後加上 –with-curl
在這篇文章中,我們一起來看看如何使用curl庫,並看看它的其他用處,但是接下來,我們要從最基本的用法開始
基本用法:
第一步,我們通過函數curl_init()建立一個新的curl會話,代碼如下:
// create a new curl resource
$ch = curl_init();
?>
我們已經成功建立了一個curl會話,如果需要擷取一個url的內容,那麼接下的一步,傳遞一個url給curl_setopt()函數,代碼:
// set url and other appropriate options
curl_setopt($ch, curlopt_url, “http://www.google.com/”);
?>
1 2 3 4
http://www.bkjia.com/PHPjc/445399.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/445399.htmlTechArticle代碼如下: $ch = curl_init(); $c_url = http://www.bkjia.com; $c_url_data = product_type=.$type.; curl_setopt($ch, curlopt_url,$c_url); curl_setopt($ch, curlopt_post, 1); curl_se...