Monday, June 7, 2010

php curl

curl is a command line tool for transferring data with URL syntax

Curl is free and open software that compiles and runs under a wide variety of operating system

Php curl is basically used to fetch data from the web, the following code will fetch the yahoo.com home page

$url = "http://www.yahoo.com";

$ch = curl_init(); // Initialize a CURL session.

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // Return Page contents.

curl_setopt($ch, CURLOPT_URL, $url); // Pass URL as parameter.

$result = curl_exec($ch); // grab URL and pass it to the variable.

curl_close($ch); // close curl resource, and free up system resources.

echo $result; // Display page contents.

?>

Curl_init() : initialize a new session and return a CURL