Saturday, 11 February 2012

curl_get_contents()

<?php
function curl_get_contents($url) {
 // Initiate the curl session
 $ch = curl_init();
 // Set the URL
 curl_setopt($ch, CURLOPT_URL, $url);
 // Removes the headers from the output
 curl_setopt($ch, CURLOPT_HEADER, 0);
 // Return the output instead of displaying it directly
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 // Execute the curl session
 $output = curl_exec($ch);
 // Close the curl session
 curl_close($ch);
 // Return the output as a variable
 return $output;
}
?>
This function is just like file_get_contents. To use it, use the following piece of code:
<?php
$output = curl_get_contents('http://www.example.com/');
echo $output;
?>
 
 
 
 

http://www.fusionswift.com/posts/2010/02/curl-vs-file_get_contents/
http://stackoverflow.com/questions/555523/file-get-contents-vs-curl-what-has-better-performance
http://www.php.net/manual/en/wrappers.php.php

2 comments:

  1. Interesting one. Keep posting such kind of information on your blog. I bookmarked it for continuous visit.
    html5 player| html5 video player

    ReplyDelete