首页/Home PHP Common Programming A Short Example To Show How To Use Curl

A Short Example To Show How To Use Curl

PrintE-mail
Sunday, 03 February 2008 17:00  

This is a short example to illustrate the use of Curl.

Note: You should make sure that the extension php5-curl is installed. If not, open a terminal, type:

sudo apt-get install php5-curl

<?php
/**
* A simple example that gets an HTTP page.
*/

$ch = curl_init();

curl_setopt ($ch, CURLOPT_URL, 'http://www.msn.com/');
curl_setopt ($ch, CURLOPT_HEADER, 0);

$data = curl_exec ($ch);

curl_close ($ch);

if (!
$data)
{
die(
sprintf('Error [%d]: %s', curl_errno($ch), curl_error($ch)));
}
else
{
echo
$data;
}
?>