" /> PHP: Using PHP's cURL module to fetch the example.com homepage - Manual
downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

cURL Functions> <Examples
Last updated: Fri, 09 Jul 2010

view this page in

Once you've compiled PHP with cURL support, you can begin using the cURL functions. The basic idea behind the cURL functions is that you initialize a cURL session using the curl_init(), then you can set all your options for the transfer via the curl_setopt(), then you can execute the session with the curl_exec() and then you finish off your session using the curl_close(). Here is an example that uses the cURL functions to fetch the example.com homepage into a file:

Example #1 Using PHP's cURL module to fetch the example.com homepage

<?php

$ch 
curl_init("http://www.example.com/");
$fp fopen("example_homepage.txt""w");

curl_setopt($chCURLOPT_FILE$fp);
curl_setopt($chCURLOPT_HEADER0);

curl_exec($ch);
curl_close($ch);
fclose($fp);
?>


add a note add a note User Contributed Notes
Using PHP's cURL module to fetch the example.com homepage
cmnajs at gmail dot com
08-Jan-2009 08:57
Following code returns the curl output as a string.

<?php
       
// create curl resource
       
$ch = curl_init();

       
// set url
       
curl_setopt($ch, CURLOPT_URL, "example.com");

       
//return the transfer as a string
       
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

       
// $output contains the output string
       
$output = curl_exec($ch);

       
// close curl resource to free up system resources
       
curl_close($ch);     
?>

cURL Functions> <Examples
Last updated: Fri, 09 Jul 2010
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites