This article mainly introduces the Curl encapsulation class Curl implemented by php. class. php Usage, detailed analysis of the Curl encapsulation Class Definition and related usage skills in the form of a complete instance, has some reference value, you can refer to the example in this article to describe the Curl encapsulation class Curl implemented by php. class. php usage. Share it with you for your reference. The details are as follows:
$ Val) {$ sets [] = $ key. '= '. urlencode ($ val) ;}$ fields = implode ('&', $ sets);} curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ fields );} else if ('put' ==$ method) {curl_setopt ($ ch, CURLOPT_PUT, true) ;}// curl_setopt ($ ch, CURLOPT_PROGRESS, true ); // curl_setopt ($ ch, CURLOPT_VERBOSE, true); // curl_setopt ($ ch, CURLOPT_MUTE, false); curl_setopt ($ ch, CURLOPT_TIMEOUT, 10 ); // Set curl timeout seconds if (strlen ($ userAgent) {cur Rochelle setopt ($ ch, CURLOPT_USERAGENT, $ userAgent);} if (is_array ($ httpHeaders) {curl_setopt ($ ch, CURLOPT_HTTPHEADER, $ httpHeaders );} $ ret = curl_exec ($ ch); if (curl_errno ($ ch) {curl_close ($ ch); return array (curl_error ($ ch ), curl_errno ($ ch);} else {curl_close ($ ch); if (! Is_string ($ ret) |! Strlen ($ ret) {return false;} return $ ret;} function post ($ url, $ fields, $ userAgent = '', $ httpHeaders = '', $ username = '', $ password ='') {$ ret = Curl: execute ('post', $ url, $ fields, $ userAgent, $ httpHeaders, $ username, $ password); if (false ===$ ret) {return false;} if (is_array ($ ret) {return false;} return $ ret ;} function get ($ url, $ userAgent = '', $ httpHeaders ='', $ username = '', $ pas Sword = '') {$ ret = Curl: execute ('GET', $ url,'', $ userAgent, $ httpHeaders, $ username, $ password ); if (false ===$ ret) {return false;} if (is_array ($ ret) {return false;} return $ ret;} function create () {$ ch = null; if (! Function_exists ('curl _ init ') {return false;} $ ch = curl_init (); if (! Is_resource ($ ch) {return false;} return $ ch ;}}?>
GET usage:
$curl = new Curl();$curl->get('http://www.XXX.com/');
POST usage:
$curl = new Curl();$curl->get('http://www.XXX.com/', 'p=1&time=0');
I hope this article will help you with php programming.
For more articles on Curl encapsulation class Curl. class. php Usage instance analysis implemented by php, refer to PHP Chinese website!