Fetching Remote Web Pages With CURL and PHP
Written by Cory S.N. LaViska on April 8th, 2008
The simplest way to retrieve a remote webpage using PHP’s cURL library.
This is a very brief example of how to use PHP’s cURL Library to retrieve the source of a remote webpage:
<?php
$c = curl_init();
curl_setopt($c, CURLOPT_URL, "http://example.com/");
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($c);
curl_close($c);
?>
$c = curl_init();
curl_setopt($c, CURLOPT_URL, "http://example.com/");
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($c);
curl_close($c);
?>
CURLOPT_RETURNTRANSFER is a predefined constant that tells cURL to return the output to a variable instead of displaying it in the browser. Visit the PHP Manual for a list of all CURL predefined constants and their uses.
The source of the remote file will be stored as a string in $data.
To use the cURL library, you must have the cURL PHP extension installed. See the PHP Manual for information about Installing CURL.

Comments
#1 Kim Steinhaug on Apr 9th, 2008