Php CURL is a good function for several small application segments of phpcurl. Below are some good segments added to favorites. 1. test whether the website is running normally & nbsp; & lt ;? If (isDomainAvailible ('http: // gz.itownet.cn ') small applications of php curl
Php's CURL is a good feature. Below are some of the best clips added to favorites:
1. test whether the website is running normally.
2 can replace file_gecontents operations
function file_get_contents_curl($url) {$ch = curl_init();curl_setopt($ch, CURLOPT_HEADER, 0);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Set curl to return the data instead of printing it to the browser.curl_setopt($ch, CURLOPT_URL, $url);$data = curl_exec($ch);curl_close($ch);return $data;}
3. save all images of a website
function getImages($html) { $matches = array(); $regex = '~http://somedomain.com/images/(.*?)\.jpg~i'; preg_match_all($regex, $html, $matches); foreach ($matches[1] as $img) { saveImg($img); }}function saveImg($name) { $url = 'http://somedomain.com/images/'.$name.'.jpg'; $data = get_data($url); file_put_contents('photos/'.$name.'.jpg', $data);}$i = 1;$l = 101;while ($i < $l) { $html = get_data('http://somedomain.com/id/'.$i.'/'); getImages($html); $i += 1;}
4. FTP application
// open a file pointer$file = fopen("/path/to/file", "r");// the url contains most of the info needed$url = "ftp://username:password@mydomain.com:21/path/to/new/file";$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);// upload related optionscurl_setopt($ch, CURLOPT_UPLOAD, 1);curl_setopt($ch, CURLOPT_INFILE, $fp);curl_setopt($ch, CURLOPT_INFILESIZE, filesize("/path/to/file"));// set for ASCII mode (e.g. text files)curl_setopt($ch, CURLOPT_FTPASCII, 1);$output = curl_exec($ch);curl_close($ch);