: This article mainly introduces two basic phpCURL instances. For more information about PHP tutorials, see. To start preparation, first find extension = php_curl.dll in the php. ini file, remove ";", and enable curl support.
Curl_init (); // initialize curl
Curl_close (); // link curl
Curl_exec (); // perform the curl operation
Curl_setopt (int ch, string option, value) // sets the curl option
Option is the desired attribute, and value is the corresponding value.
The basic attributes of option are as follows:
CURLOPT_URL // you can specify the URL to capture a webpage.
CURLOPT_POST // use php for the httppost operation and set the option to a non-zero value
CURLOPT_POSTIELDS // all data of the post operation of the httppost operation
CURLOPT_PETURNTRANSFER // whether to return the content obtained on the page. if the value is not zero
I. Basic example
$ Curl = curl_init (); // initialize the curl object $ curl_setopt ($ curl, CURLOPT_URL, 'www .baidu.com '); // you can specify the URL of the captured page $ curl_setopt ($ curl, CURLOPT_HEADER, 1); // include a header in the output and set the value to non-zero $ response = curl_exec ($ curl); // execute the operation, run curlcurl_close ($ curl); // close the operation.
II. post data
$ Data = array ('name' => 'trany', 'age' => '12'); $ curl = curl_init (); // initialize the curl object $ curl_setopt ($ curl, CURLOPT_URL, 'www. BAIDU. COM '); // set the page capture address $ curl_setopt ($ curl, CURLOPT_POST, 1); // do httppost to submit $ curl_setopt ($ curl, CURLOPT_POSTFIELDS, $ data ); // pass the value $ response = curl_exec ($ curl); // execute the curl_close ($ curl) operation; // close the operation